[Newbies] test for exception

John Almberg jalmberg at identry.com
Tue Aug 14 20:02:05 UTC 2007

I have a setter method that tests input for validity using 'assert'.  
It looks like this:

aVariableName: aNumber
	self assert: [(aNumber >= self minValue) & (aNumber <= self maxValue)]
		description: 'invalid value'.
	aVariableName := aNumber.

The program needs to blow up if an invalid number is assigned. I  
don't want to just quietly ignore the invalid assignment. That's why  
I have this assertion.

Anyway, the assertion blows up just fine, but now I'd like to write a  
test that checks to see what happens if I try to assign an invalid  

I *think* I should use something like:

	self should: [anObject aVariableName = anInvalidNumber] raise: ???

raise: is supposed to get the ExceptionEvent, but I'm not sure how to  
find out which event this would be. The debugger doesn't seem to show  
this when the assertion fails.

How do I know which exception event is raised? Or am I on the wrong  
track completely?

Thanks: John


More information about the Beginners mailing list