[nem-en] Semantics of 'expose' macro construct when an exception is thrown.

Kamil Skalski kamil.skalski at gmail.com
Wed Dec 7 18:05:01 CET 2005


2005/12/7, Gerard Murphy <g.j.murphy at sageserpent.com>:
> Hello,
>
> I was investigating why the following class doesn't pass a unit test, when I
> noticed that exceptions thrown in an 'expose' block are not propagated out
> of the block.
>
> This seems surprising. I would indeed expect the class invariant to be
> checked on the object specified in the 'expose' statement, regardless of
> whether the block completes normally or throws an exception: but in the
> latter case I would also expect the exception to be rethrown and propagated
> after checking the invariant (assuming the invariant wasn't violated).

Indeed it is a bug. The Spec#'s behaviour for exceptions is described
with details in
http://research.microsoft.com/specsharp/papers/krml135.pdf

>From the section about expose it seems that exceptions are always
propagated from expose block, we should also do this of course.

What differs is that they introduced distinction between checked and
unchecked exceptions. For checked exceptions (those specified at
method's signature as possible to be thrown) the invariant is checked
even after exceptionally breaked expose block, while for other
exceptions the check is disabled. We do not support checked exception
at this time, so we simply need to always propagate exceptions.


>
> Here's the code.

Thanks for reporting this issue, I will fix an expose macro in a moment.

>
> As far as I can see, the invariant is not being violated during execution of
> the unit test: so I would expect to see the bogus exception being propagated
> (as opposed to either a Nemerle.Assertion exception being propagated or
> execution continuing normally after the 'expose' block).
>

The exception should be propagated out of the block in this case.

--
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list