Version 4 (modified by nicobn, 11 years ago)

Exceptions and assertions

The Jaws API uses two types of language-level constructs to handle error cases: exceptions and assertions. To know how they are handled, please refer to the Jaws_Toolkit page.


When a run-time error occurs, exceptions should be used in most cases. Jaws has its own exception class, called Jaws_Exception. It is used slightly differently than the standard Exception class but implements all of its functionalities, as it extends it.


The constructor of the Jaws_Exception class has the following syntax:

Jaws_Exception::__construct(integer $lvl, string $message)

$message is the exception message; $lvl can be one of the following exception severity level codes:

  • Jaws_Exception::EC_ERR - A non-fatal error
  • Jaws_Exception::EC_FATERR - A fatal error
  • Jaws_Exception::EC_CORE - A fatal error caused internally, most probably by a programming error or an incoherency
  • Jaws_Exception::EC_UNKNOWN - Unknown: do not use this code

Additional methods

Additionally to the methods already implemented by the Exception class, the Jaws_Exception class also implements the following methods:

  • Jaws_Exception::getLvl() - Get the exception's severity level
  • Jaws_Exception::getLvlStr() - Get the severity level as a string
  • Jaws_Exception::getBacktrace() - Return the backtrace information in a string, using the Jaws' customized backtrace parser


Assertions are used to avoid programming errors (EC_CORE exceptions). In production, the evaluation of assertions is disabled to fasten the execution. Assertions should be used only when, in the end, the programming error will be caught anyway, but in a much less favourable, elegant and meaningful way. Assertions should be used as much as possible instead of Jaws_Exception::EC_CORE exceptions.

< Click here to go back to Jaws 2 Internals section