ExceptionalEvent collections
Occasionally, it is desirable to use a single handler for several nonhierarchically related exceptions. To handle this situation, the when:do: syntax has been extended to allow an ExceptionalEvent collection as the when argument. ExceptionalEvent collections are created by sending the vertical bar (|) message to an instance of ExceptionalEvent as follows:
In class ExceptionalEvent:
| anExceptionalEvent
"Answer a new ExceptionalEvent collection
containing the receiver and anExceptionalEvent."
In the ExceptionalEvent collection:
| anExceptionalEvent
"Add anExceptionalEvent to the exceptions stored in the receiver."
Given these definitions, it is possible to write the following:
[ "Some code that could cause several exceptions" ]
when: Type1Exception | Type2Exception | Type3Exception
do: [:signal | signal exitWith: 'I expected this exception'].
ExceptionalEvent collections can be stored in a variable and later referred to:
ExpectedExceptions :=
Type1Exception | Type2Exception | Type3Exception.
"Some code that could cause several exceptions"
when: ExpectedExceptions
do: [:signal | signal exitWith: 'I expected this exception'].
ExceptionalEvent collections cannot be signaled.
Within the body of a handler block, sending exception to the passed-in instance of Signal always answers the particular exception that was signaled.
Last modified date: 01/29/2015