Search
 
SCRIPT & CODE EXAMPLE
 

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;
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: try without catch 
Javascript :: react native panresponder on click 
Javascript :: Find the count of a letter in a string 
Javascript :: take one character in end of string javascript 
Javascript :: The Lodash Array Remove Method 
Javascript :: Destructuring of array in ES6 
Javascript :: can we add string and int in javascript 
Javascript :: difference between || and ?? in js 
Javascript :: vscode react snippets 
Javascript :: javascript greater than or equal to 
Javascript :: set.contains in javascript 
Javascript :: read and save excel with react 
Javascript :: counter react 
Javascript :: firebase integration in react 
Javascript :: print console.log 
Javascript :: template literals in js 
Javascript :: mongoose create text index to search for text 
Javascript :: split function in javascript 
Javascript :: javascript return function 
Javascript :: Javascript async await & Promise 
Javascript :: Javascript "For..in Loop" Syntax 
Javascript :: promise in js 
Javascript :: javasript object 
Javascript :: firebase timestamp to date react 
Javascript :: + sign javascript 
Javascript :: dispatch store 
Javascript :: module export javascript 
Javascript :: empty array 
Javascript :: js append html in div after 
Javascript :: async await map 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =