Re: OCL: dealing with exceptions



Date view Thread view Subject view Author view Attachment view

From: Brian Smith (brian-l-smith@uiowa.edu)
Date: Wed 29 May 2002 - 12:36:53 BST


Jason,

I assume you are referring to the expression:

context Bank:deposit(x : int)
    post: if x > 0 then balance = balance@pre + x
          else raised DepositException endif

I suppose, what I am thinking is that, if DepositException is raised, then the postcondition is never evaluated to a value (Boolean or otherwise). Therefore, during type-checking, the type-checker should more-or-less ignore all of the "code-paths" that raise exceptions. For example, in the following constraint, if the exception is raised then the method never returns a value (because the "if" expression doesn't evaluate to any value) so the expression is type-safe. This is the way the programming language ML (and O'Caml) works and I find it pretty intuitive:

context EZMath::binary_sqrt(x : int)
post: result = if (x/2)*(x/2) <> x
               then raised RootException(x)
               else x/2
               endif     -- hmm... is "endif" necessary?

- Brian

Jason Gorman wrote:

>If it's a boolean expression shouldn't it be something along the lines of 
>
>exception.oclIsTypeOf(DepositException)
>
I wrote:

>context Bank::deposite(x : int)
>
>post: if x > 0 then balance = balance@pre + x else raised 
>
>DepositException end if
>

Date view Thread view Subject view Author view Attachment view