When a JavaScript exception is caught in a snippet and the exception is output using console.log, it appears as an empty object.
Example:
try {
let foo = null;
foo.bar;
} catch(exception) {
console.log(exception);
console.log("As opposed to:")
console.error(exception);
}
"{}"
. Most browsers console seem to call a special toString method (including the call-stack as a second line) that is not specified anywhere (the available toString returning only ErrorInstance#ConstructorName: ErrorInstance#Message). Maybe that would be enough? (Would still require anif(object instanceof Error)
which will likely slow down even more the stringification algo, for all logs...).error
(which seems to be aware of the special toString) would be satisfactory.console.log()
or withconsole.error()
? Your post was the closest I could find. My own opinion is thatconsole.error()
is preferable. And as I understand this comment of yours, you agree with me?console.error()
would suit the majority of use cases.