tips
[Top] [All Lists]

REALbasic Tip: Catching unhandled exceptions

To: "REALbasic Tips" <realbasic-tips at lists dot realsoftware dot com>
Subject: REALbasic Tip: Catching unhandled exceptions
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Wed, 04 Sep 2002 15:15:37 -0500
You have probably seen the error message "Unhandled NilObjectException
raised" or "OutOfBounds Exception raised" when running your application in the IDE. An Unhandled NilObjectException occurs when you access an object that hasn't been created yet. For example, the following code will produce
this error:

Dim f as folderitem
f.name = "foo"

The folderitem "f" was declared but never created. What is missing is a call
to a function that creates a folderitem:

f = GetFolderItem("Foobar")

An OutOfBounds exception occurs when you attempt to access an element of an
array that does exist. Accessing element 10 of a 5 element array for
example.

When an exception occurs, it's nice to know what the current values of
various variables and properties are so you can determine what caused the problem. The problem is that the error causes your app to stop running and
exit back to the design environment of REALbasic.

The solution is to include an exception statement at the end of the method and then add a breakpoint following the exception statement. If an exception occurs, the code will immediately call the code that follows the exception
statement and your breakpoint will drop you into the debugger. The code
above would then look like this:

Dim f as folderitem
f.name = "foo"
Exception
(breakpoint here)

This technique works particularly well in REALbasic v4.5 because the new
version can save breakpoints in your project so the breakpoints will still
be there when you open your project again later.

If you haven't upgraded to REALbasic v4.5 you can do so at:

<http://www.realbasic.com/store/index.html>

This tip was submitted by Paul Harvey.
--
Geoff Perlman
President and CEO
REAL Software, Inc.
512-328-7325 x711 (voice)
512-328-7372 (fax)


 - - - - - - - - - -
Got a useful tip to share? Send it to us at:
REALbasic-tips at lists dot realsoftware dot com dot
To unsubscribe from the Tips list, send an email to
<mailto:realbasic-tips-off at lists dot realsoftware dot com>


<Prev in Thread] Current Thread [Next in Thread>
  • REALbasic Tip: Catching unhandled exceptions, Geoff Perlman <=