What types of errors get into try-catch statements in Javascript?

If i write

try { null = foobar } catch(e) { alert( e ) };

does not warn anything, but is written to the console ReferenceError. Nonetheless,

try { barfoo = foobar } catch(e) { alert( e ) };

shows warning c ReferenceError.

So the question is: what types of errors in what context fall into try-catch statements?

+4
source share
1 answer

So, your first line of code is invalid JavaScript syntax. This is why you get:
ReferenceError: Invalid left-hand side in assignment(You cannot assign vars to null)

The second line - this syntax, but throws:
ReferenceError: foobar is not defined.

, , - , , JavaScript , , .

, @Matt:

JavaScript . , .

, JavaScript, , , , ? , unatchable Error ( SyntaxError ReferenceError). , , - try/catch , , .

+4

Source: https://habr.com/ru/post/1546810/


All Articles