Monday 15 March 2010

javascript - Why error is caught when calling to a missing function, and not on a bad statements? -



javascript - Why error is caught when calling to a missing function, and not on a bad statements? -

please see code:

<!doctype html> <html> <body> <p id="p1"></p> <script> seek { alllllllert("hello.........!"); } catch(err) { document.getelementbyid("p1").innerhtml = err.message; } </script> </body> </html>

when code running error caugth , come in grab block.

however, why not happaning in next code:

<!doctype html> <html> <body> <p id="p1"></p> <script> seek { int n = 3; document.getelementbyid("p1").innerhtml = n; } catch(err) { document.getelementbyid("p1").innerhtml = err.message; } </script> </body> </html>

writing int n = 3 cannot compile on javascript, , know need write var n =3. so, why don't exception message?

int n = 3; invalid syntax, prevents entire <script> block beingness parsed.

therefore, catch block doesn't exist.

javascript

No comments:

Post a Comment