When an Error is thrown, the code below the thrown line doesn't execute.
Hence, its impossible to return a value immediately after throwing an error. However, you can send a value along with the error and catch it later.
So,I am Assuming that you want to throw a value with an error...Here's how to do that...
Hope this is somewhat helpful
function UserException(message) {
this.message = message;
this.name = 'UserException';
}
// Make the exception convert to a pretty string when used as a string
// (e.g., by the error console)
UserException.prototype.toString = function() {
return `${this.name}: "${this.message}"`;
}
let v = 1010 //
let val = ((e, v) => {
setTimeout(() => {
console.log("value from error"+" :"+e.message,",variable v"+" :"+v);
throw(e);
}, 0); // will throw in console
})(new UserException(v), v) //
v, it doesn't throw any exceptions.