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);

Last edited Feb 25, 2013 at 12:26 PM by MFidemraizer, version 2

Comments

No comments yet.