Re: OCL: dealing with exceptions



Date view Thread view Subject view Author view Attachment view

From: Anneke Kleppe (A.Kleppe@klasse.nl)
Date: Mon 27 May 2002 - 15:49:42 BST


Hi Brian,

There are two ways in which to specify exceptions in OCL, depending on how 
your exceptions are modelled.
When an exception is considered to be a specific operation that is called 
when the condition occurs, you can use the following:

context yourClass:operationThatThrowsException() : SomeResultType
pre: -- none
post: someCondition implies exceptionHandler^handlingOperation().isSent()

someCondition can be written in exactly the same manner as in every other 
OCL expression. This type of expression, indicating a message being sent, 
is new to the OCL 2.0.

When an exception is specified as a class, of which a new instance has to 
be created when the condition occurs, you can use something like the following:

context yourClass:operationThatThrowsException() : SomeResultType
pre: -- none
post: Let e: Exception
       in someCondition implies ( self.thrownExceptions->includes( e ) and
                                  e.isNew() )

But as you can see, it all depends on how you have modelled your exceptions 
in the UML part of your specification. Here I assume that 'yourClass' has 
an association with the class 'Exception', called 'thrownExceptions'. But 
many different approaches can be used.

Hope this helps,
Anneke Kleppe

At 12:13 PM 22-05-2002 -0500, you wrote:
>How can I use OCL to specify the conditions under which a particilar 
>exception is thrown by an operation? I have looked at the OCL 
>specification and there seems to be no way to do it.
>
>I am looking for a way to specify exceptions that will type-check.
>
>Any references to information about this topic are greatly appreciated.
>
>Thanks,
>Brian
>
>
>
>
>To remove yourself from this list please mail puml-list-request@cs.york.ac.uk
>with a message containing the word "unsubscribe".
>

Klasse Objecten
Chalonhof 153
NL - 3762 CT Soest
The Netherlands
voice: +31(0)35-6037646
fax: +31(0)35-6037647
http://www.klasse.nl

Date view Thread view Subject view Author view Attachment view