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", function () {
    this.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();

Last edited Apr 6, 2013 at 2:21 PM by MFidemraizer, version 3


No comments yet.