arozwalak
7/13/2015 - 9:06 AM

Javascript: Error Object

Javascript: Error Object

try {
  // something bad happened, throw an error
  throw {
    name: "MyErrorType", // custom error type
    message: "Ooops",
    extra: "This was rather embarrasing",
    remedy: genericErrorHandler // who should handle it
  };
} catch (e) {
  // inform the user
  alert(e.message); // "oops"
  
  // gracefully handle the error
  e.remedy(); // calls genericHandler()
}