logo       

test for exception: msg#00126

lang.smalltalk.squeak.beginners

Subject: test for exception

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 number.

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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise