Last active
August 29, 2015 14:19
-
-
Save robsonalves/7704156635437fe7d5b3 to your computer and use it in GitHub Desktop.
instanceof Practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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