[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] Exception Handling
From: |
Jerry Mead |
Subject: |
[Help-smalltalk] Exception Handling |
Date: |
Sat, 19 Jan 2002 12:17:31 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011221 |
Smalltalk users --
I am having the following problem -- and I think it might be as a
result of my not understanding how CoreException interface.
The attached smalltalk program lets me test how CoreExceptions
work. The first line adds an exception object to Smalltalk. As is
the exception has 'isResumable' set to 'true'. In this form the program,
when executed gives the following output:
-----------------------------------------
st> FileStream fileIn:'testExc.st'!
st> (Test new: 9) doit!
6
'too big'
5
-----------------------------------------
which seems to me what should happen. After the exception is
handled, execution resumes just after the exception occurred.
Now if the file is modified so that 'isResumable' is set to
'false', I get the following result:
-----------------------------------------
st> FileStream fileIn:'testExc.st'!
st> (Test new: 9) doit!
6
'too big'
Object: MethodContext new: 8 "<0x601982f8>" error: did not understand
#thisContext
MethodContext(Object)>>#primError:
MessageNotUnderstood(Exception)>>#defaultAction
[] in Exception class>>#coreException
MessageNotUnderstood(Signal)>>#activateHandler:
MessageNotUnderstood(Exception)>>#signal
MethodContext(Object)>>#doesNotUnderstand:
Signal>>#activateHandler:
CoreException>>#signal
Obj>>#try:
[] in Test>>#doit
BlockClosure>>#on:do:
Test>>#doit
UndefinedObject>>#executeStatements
-----------------------------------------
If someone can help me with this I will be most grateful.
Jerry Mead
______________________________________________________________________
Jerry Mead, Assoc Prof email: address@hidden
Computer Science Department URL: http://www.eg.bucknell.edu/~mead
Bucknell University
Lewisburg, PA 17837
Smalltalk at:#exc put: ((CoreException new) isResumable: false)!
Object subclass: #Obj
instanceVariableNames: 'val'
classVariableNames: ''
poolDictionaries: ''
category: nil!
!Obj class methodsFor: 'initialization'!
new: v
|o|
o := self new.
o init: v.
^o
!!
!Obj methodsFor: 'initialization'!
init: v
val := v
!
try: v
(v < val) ifTrue: [ v printNl ]
ifFalse: [ exc signal ]
!!
Object subclass: #Test
instanceVariableNames: 'this val'
classVariableNames: ''
poolDictionaries: ''
category: nil!
!Test class methodsFor: 'initialization'!
new: v
|o|
o := self new.
o init: v.
^o
!!
!Test methodsFor: 'initialization'!
init: v
val := v
!
doit
this := Obj new: val.
[
this try: 6.
this try: 10.
this try: 5
] on: exc do: [:x| 'too big' printNl ]
!!
- [Help-smalltalk] Exception Handling,
Jerry Mead <=