Custom exception type

Manki picture Manki · Jan 21, 2009 · Viewed 108.3k times · Source

Can I define custom types for user-defined exceptions in JavaScript? If so, how would I do it?

Answer

jon077 picture jon077 · Jul 16, 2009

From WebReference:

throw { 
  name:        "System Error", 
  level:       "Show Stopper", 
  message:     "Error detected. Please contact the system administrator.", 
  htmlMessage: "Error detected. Please contact the <a href=\"mailto:[email protected]\">system administrator</a>.",
  toString:    function(){return this.name + ": " + this.message;} 
};