Creating custom exceptions
Any project in the world may need exceptions. Exceptions are a modern and solid way of throwing errors for later handling them.
Creating new exception types is easy: it is just about deriving the
$global.joopl.ExceptionBase** class:
$namespace.register("joopl.Samples");
$global.joopl.Samples.MyException = $def({
$constructor: function() {
this.$base.$ctor({ message: "My custom exception message" });
},
$members: {
},
$extends: $global.joopl.ExceptionBase
});
// Throwing the exception.
throw $new($global.joopl.Samples.MyException);