Try to catch an error in javascript - get more error information

How can I get more error data from a javascript catch?

Are there more options to get more details about the captured error.

try { var s = null; var t = s.toString(); } catch(err) { alert(err); } 
+6
source share
3 answers

The error object contains several properties that you can use. One property that you can use to receive an error message is .message , as in:

 catch(err) { alert(err.message); } 

The .name property returns the type of error, as in:

 catch(err) { x = err.name; // ... do something based on value of x } 

The name describes the type of error, and the .name value can be: EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError . You can solve this error differently, depending on the type of error returned by the .name property.

A good tutorial can be found on JavaScriptKit . This is also an article about the bug object in the Mozilla Developer Network .

+8
source

Check out this link: Link to Error.prototype

You basically have err.name and err.message .

You also have several extensions for a particular provider:

Microsoft => err.description and err.number .

Mozilla => err.fileName , err.lineNumber and err.stack .

+5
source
 function message() { try { } catch(err) { alert(err.message); } } 

SEE HERE and HERE

0
source

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


All Articles