code_junkie

Custom Exceptions in JavaScript

Nov 13th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. throw {
  2. name: "System Error",
  3. level: "Show Stopper",
  4. message: "Error detected. Please contact the system administrator.",
  5. htmlMessage: "Error detected. Please contact the <a href="mailto:[email protected]">system administrator</a>."
  6. }
  7.  
  8. function MyError(message) {
  9. this.message = message;
  10. }
  11.  
  12. MyError.prototype = new Error;
  13.  
  14. function MyError(message) {
  15. this.message = message;
  16. }
  17.  
  18. MyError.prototype = new Error;
  19.  
  20. function MyError(message) {
  21. this.message = message;
  22. }
  23.  
  24. MyError.prototype = new Error;
  25.  
  26. try {
  27. something();
  28. } catch(e) {
  29. if(e instanceof MyError)
  30. doSomethingElse();
  31. else if(e instanceof Error)
  32. andNowForSomethingCompletelyDifferent();
  33. }
Add Comment
Please, Sign In to add comment