Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

property of exception object javascript

//It contains 2 properties: message : the error description,
//a human readable message thatshould explain what error happened.
//name : the type of error occurred (assumes the value of the specific error object name, 
//for example, TypeError or SyntaxError )

//Custom properties of error
function doWork() {
  try {
    doFailSomeWay();
  } catch (err) {
    throw new Error('Failed in some way', { cause: err });
  }
  try {
    doFailAnotherWay();
  } catch (err) {
    throw new Error('Failed in another way', { cause: err });
  }
}

try {
  doWork();
} catch (err) {
  switch(err.message) {
    case 'Failed in some way':
      handleFailSomeWay(err.cause);
      break;
    case 'Failed in another way':
      handleFailAnotherWay(err.cause);
      break;
  }
}
 
PREVIOUS NEXT
Tagged: #property #exception #object #javascript
ADD COMMENT
Topic
Name
9+3 =