0
// Create an object type UserException  
function UserException (message){  
  this.message=message;  
  this.name="UserException";  
}  

// Make the exception convert to a pretty string when used as  
// a string (e.g. by the error console)  
UserException.prototype.toString = function (){  
  return this.name + ': "' + this.message + '"';  
}  

// Create an instance of the object type and throw it  
throw new UserException("Value too high");

How will this be used?

DarkLightA
  • 14,980
  • 18
  • 49
  • 57

1 Answers1

2

This is how you can create objects in javascript, in this case, a UserException object with a toString function. It might be used like so:

try {
    throw new UserException("something went wrong");
} catch(ex) {
    console.log(ex);
}
Ian Wetherbee
  • 6,009
  • 1
  • 29
  • 30