RuntimeException

From REALbasicWiki

(Redirected from Exceptions)
Jump to: navigation, search
Overall article skill Skill ranges from beginner (green) to expert (red)
RuntimeException class
Available on Mac OS X Linux Windows
General
Superclass Object
Interfaces none
Constants

none

Methods

none

Properties
Events

none

NOTE: You can get descriptions of the items above from the REALbasic documentation.


RuntimeException is the base class for all exception classes. Only instances of RuntimeException or its subclasses can be raised as exceptions.

[edit] What's an exception ?

There is a problem when you use an object: each time you do that you should check if an error occurred and which error occurred. If so, you should display an informative message to the user but also should you bypass the execution of the following instructions which rapidly becomes a nightmare of if-then-else statement. By contrast, a runtime exception can be raised anywhere at anytime. It stops normal execution and it will propagate until it is caught by a so-called exception handler. In REALbasic, an exception handler can be either a try-catch statement or an exception statement.

Consider the following scheme:

  1. Application shows its Window1
  2. Window1 has a button (called aButton) on which user has clicked
  3. aButton calls a method (called aMethod) and unfortunately, such method raises a RuntimeException.

The runtime environment then do the following:

  • It drops execution of all the rest of aMethod, looking for any exception handler which could process the RuntimeException
  1. It first looks in aMethod itself
  2. If it does not find one, it looks in the object which called aMethod. This is Window1 in our example.
  3. If Window1 does not implement any exception handler, then the RuntimeException is forwarded to the application event UnhandledException. This is your last chance of processing the RuntimeException
  4. If you do not intercept the exception, then REALbasic will automatically display a message "An exception of class ... was not handled. The application must shut down."


Personal tools
related