How do I get the first line only of a console.log(ex.stack)>
For example I only want this:
TypeError: Object #<Object> has no method 'debug'
Out of this:
TypeError: Object #<Object> has no method 'debug'
at eval at <anonymous> (unknown source)
at eval (native)
at Object._evaluateOn (unknown source)
at Object._evaluateAndWrap (unknown source)
at Object.evaluate (unknown source)
If you want the error message, just grab it directly. There's no need to parse it out from the full stack trace:
var Object = {};
try {
Object.debug();
} catch(ex) {
console.log(ex.message);
}
If that's not possible for whatever the reason, the stack trace appears to be nothing but a string:
console.log(typeof ex.stack);
string
... so pick your favourite string manipulation technique:
var Object = {};
try {
Object.debug();
} catch(ex) {
console.log(ex.stack.split("\n", 1).join(""));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With