Skip to content

Instantly share code, notes, and snippets.

@robsonalves
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsonalves/7704156635437fe7d5b3 to your computer and use it in GitHub Desktop.
Save robsonalves/7704156635437fe7d5b3 to your computer and use it in GitHub Desktop.
instanceof Practice
function ValidException(number, message) {
this.message = message;
this.name = "Teste prático";
this.number = number;
}
function LogicException(number, message) {
this.message = message;
this.name = "Teste prático";
this.number = number;
}
function myFunction(dayOfWeek) {
if (dayOfWeek > 7) {
throw new ValidException(123, 'Day of week must be less than 7');
}
}
function doWork(value) {
try {
myFunction(value);
}
catch(e) {
if (e instanceof ValidException) {
alert(e.message);
}
}
}
doWork(90);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment