How can I get more error details from a javascript catch?
Are there more parameters to get more details from the caught error.
try {
var s = null;
var t = s.toString();
} catch(err) {
alert(err);
}
How can I get more error details from a javascript catch?
Are there more parameters to get more details from the caught error.
try {
var s = null;
var t = s.toString();
} catch(err) {
alert(err);
}
The Error Object has several properties that you can use. One property you can use to get the message of the error, 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 value of .name can be : EvalError, RangeError, ReferenceError, SyntaxError, TypeError , and URIError. You may decide to handle the error differently depending on the error type which is returned by the .name property.
A good tutorial can be found on JavaScriptKit. The is also an article on the error object at Mozilla Developer Network.
Check this link out: Reference to Error.prototype
Basically you have err.name and err.message.
You also have a few vendor-specific extensions:
Microsoft => err.description and err.number.
Mozilla => err.fileName, err.lineNumber and err.stack.