Exception handling question

Boris Gaertner Boris.Gaertner at gmx.net
Sat Aug 2 21:35:48 UTC 2003


From: Roel Wuyts <wuyts at iam.unibe.ch>


> Hello,
> I am trying out some things under 3.6 (updated till #5373).
> 
> The following statements did exactly what I thought they would:
>      [self error: 'an error'] on: Error do: [:exc | Transcript show: exc 
> class name; cr].
>      [self halt: 'a halt'] on: Halt do: [:exc | Transcript show: exc 
> class name; cr].
> They print 'Error' and 'Halt' on the Transcript.
> 
> But the following ones did not do what I expected:
>      [self error: 'an error'] on: Exception do: [:exc | Transcript show: 
> exc class name; cr].
>      [self halt: 'a halt'] on: Exception do: [:exc | Transcript show: 
> exc class name; cr].
> It prints 'Error' and then (this is what I consider weird) 
> 'UnhandledError' ?!
> 
In Squeak 3.4 #5170  the statement in question  opens a Debugger.
The 'UnhandledError' comes from  Error>>defaultAction; a
method that was recently changed. (ajh 9/4/2002)

Error>>defaultAction is sent from  Exception>>signal.
The most important point however is that Exception DOES NOT
handle Halt (in spite of the fact that Halt is a subclass of Exception.)
The code for this exception to the general rule is in 
Exception class>>handles: exception   where we read:

handles: exception
 "Determine whether an exception handler will accept a signaled exception."

 (exception isKindOf: Halt) ifTrue: [^ false].
 ^ exception isKindOf: self

Exceptions that are a kind of a Halt are handled by Halt, but not
by the superclasses (Error, Exception).
I cannot tell you the history of that exception to the general rule
that the more general exception should handle specialized
exceptions.
 

> I don't know enough to say whether this is a feature, a bug, or my 
> complete misunderstanding :-) Can somebody enlighten me?
> 
I do not think that it is a bug, but I cannot explain why the 
feature is there. Does somebody know or remember?

Greetings, Boris




More information about the Squeak-dev mailing list