How can I rethrow an error or exception in nodejs/javascript and include a custom message.
I have the following code
var json = JSON.parse(result);
you can also just continue to throw the error up your try chain. If you want to modify anything do so along the way: before the throw statement in b.
function a() {
throw new Error('my message');
}
function b() {
try {
a();
} catch (e) {
// add / modify properties here
throw e;
}
}
function c() {
try {
b();
} catch (e) {
console.log(e);
document.getElementById('logger').innerHTML = e.stack;
}
}
c();