[Newbies] test for exception
John Almberg
jalmberg at identry.com
Tue Aug 14 21:47:30 UTC 2007
Lots of digging later...
Okay! I think I found the ExceptionEvent I need. It's the
appropriately named 'AssertionFailure'.
For anyone who might be interested at some future date, the following
test works:
self should: [ anObject aSetter: anInvalidNumber] raise:
AssertionFailure.
Cool!
-- John
On Aug 14, 2007, at 4:02 PM, John Almberg wrote:
> 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
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
jalmberg at identry.com
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Beginners
mailing list