29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Notifiers c<strong>an</strong> be displayed under a number of circumst<strong>an</strong>ces. They c<strong>an</strong> be caused:<br />

• Accidentally, by sending a message to <strong>an</strong> object which has no corresponding method. This is the<br />

usual response to a program error.<br />

• Deliberately, by typing 'CTRL-C' or equivalent to break into the current execution.<br />

• Deliberately, by inserting a breakpoint. We will discuss these later.<br />

• Accidentally, by the system running out of memory.<br />

• Accidentally, by recursion occurring in the system error h<strong><strong>an</strong>d</strong>ling.<br />

5.5 Error processing<br />

H<strong><strong>an</strong>d</strong>ling run time errors in <strong>Smalltalk</strong> is slightly different to the way in which run time errors are<br />

h<strong><strong>an</strong>d</strong>led in some other l<strong>an</strong>guages. Unlike, for example, C++ on a UNIX box, you do not need to take<br />

your core dump <strong><strong>an</strong>d</strong> <strong>an</strong>alyze it using <strong>an</strong>other piece of software. Instead, the system indicates the fault<br />

<strong><strong>an</strong>d</strong> gives you a ch<strong>an</strong>ce to decide what to do next. One possibility is to interactively fix the problem.<br />

This was what was done during the exercise at the end of the last chapter.<br />

Figure 5.4: An inspector, notifier <strong><strong>an</strong>d</strong> debugger<br />

Figure 5.4 illustrates <strong>an</strong> exception notifier warning that a message ( newaAddress:for:) has been<br />

sent to <strong>an</strong> o bject which does not underst<strong><strong>an</strong>d</strong> that message. It also illustrates the debugger which would<br />

be displayed if the debug option was selected. Finally, it illustrates <strong>an</strong> inspector examining <strong>an</strong> inst<strong>an</strong>ce<br />

of class <strong>Object</strong>.<br />

5.5.1 Exception notifiers<br />

When a message is sent to <strong>an</strong> object with no corresponding method, then <strong>an</strong> exception notifier window<br />

(as illustrated in the bottom left h<strong><strong>an</strong>d</strong> corner of Figure 5.4) is displayed. This notifier is also displayed if<br />

a halt message (a breakpoint) is encountered. The exception notifier has a number of options which<br />

allow the programmer to determine what should happen next. The options are:<br />

• Debug This closes the notifier view <strong><strong>an</strong>d</strong> opens a debugger view on the error condition.<br />

• Proceed Continue as if the error had not occurred.<br />

• Terminate This terminates the current evaluation.<br />

• Copy Stack This copies the current state of the execution stack.<br />

55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!