rethrow error javascript
function bar() { // In this case, we are going to catch any errors thrown by baz(), log them to the // console, and then rethrow them. try { baz(); } catch ( error ) { console.log( "Error caught and rethrown in Bar():", error.message ); // In JavaScript, there is no special "rethrow" keyword. You simply throw() the // error that you caught. This will maintain the original stacktrace recorded by // the error as you "pass it back up" the call-stack. throw( error ); } }
javascript Rethrow an Exception
const number = 5; try { // user-defined throw statement throw new Error('This is the throw'); } catch(error) { console.log('An error caught'); if( number + 8 > 10) { // statements to handle exceptions console.log('Error message: ' + error); console.log('Error resolved'); } else { // cannot handle the exception // rethrow the exception throw new Error('The value is low'); } }