I am reading up on JavaScript exceptions:
You can nest one or more try...catch statements. If an inner try...catch statement does not have a catch block, the enclosing try...catch statement's catch block is checked for a match.
I think I understood it correctly and wrote this test code as follows:
try {
try {
throw "error";
}
} catch( e ) {
console.log( e );
}
But got this error:
Uncaught SyntaxError: Missing catch or finally after try
I know it clearly says that I am missing a catch or finally but the JavaScript documentation says my code should be valid or am I misunderstanding?
try {}block without either acatchof afinallywouldn't actually accomplish anything even if it was allowed since the only reason to put something in atryblock is so you can handle an exception. It makes sense this is an error.try { /* something */} finally {}and it would run. I also think that this would change the behavior of error handling. So this is more like javascript trying to teach programmers how to write code - how does that make sense?trydoesn't do anything without having acatchorfinally, it makes sense that the language would prohibit just atryblock all by itself. Yes, you can put an emptyfinally {}if you really want to. That at least meets the language syntax rules.42;, it does nothing yet is valid JS. Anyway I can understand the process through which such a syntax would be mandatory.