Re: CLI Exception Handling

From: Dave (noSpamdlevineNNTP2_at_wi.rr.com)
Date: 04/14/04


Date: Wed, 14 Apr 2004 05:05:38 -0500


> Actually, within a catch you are quite capable of returning to any point
> within the associated try block using leave.

"leave" is not a keyword defined in VB .NET. "__leave" is a C keyword used
in win32 SEH. It allows you to leave a try block without causing abnormal
termination and incurring a performance penalty; it does not allow you to
leave a catch block. Unless you are talking about some other leave
instruction. Or something else.

> VB actually uses this to
> implement its On Error Resume functionality. In my trivial experiments it
> appears that the VB compiler tracks statement points and always considers
> the next line to be a point where the evaluation stack is expected to be
> empty, so it resumes execution at the start of the load instructions used
to
> fill the stack. You would have to use a filter to ensure that the
exceptoin
> is actually processed by the code interested in generating a resume.
> >

That's not the same thing that I was referring to. VB allows you to resume
execution on the line of code that follows the instruction that generated
the exception, but not on the same instruction that actually generated the
exception. A true restartable exception will resume execution on the
instruction that generated the exception. This functionality is not built
into the runtime even though the spec says it does. None of the languages I
know of support it, probably because the runtime doesn't either. This
functionality does exist in win32 SEH.

The differences are deeper then that, because a user-filter executes while
running on top of the stack that generated the exception. When the catch
handler executes all finally blocks that were lower on the stack have
already run and the stack has been cleaned up. In a true resumable exception
the stack will not have been cleaned up and the finally blocks will not have
run. The resume semantics are implemented in the first pass of the two
phase SEH.

VB uses what amounts to using a goto within a method body to transfer
control to implement its resume semantics. This may look like a SEH resume
but under the hood it's not. It's unstructured exception handling, which is
completely different then the structured exception handling defined in the
spec. It appears that you cannot combine the two forms of error handling
within the same method body - vb will refuse to compile it.

> > The only way that section of the spec makes sense is that a user filter
> > could make the decision whether to resume, continue searching, or
execute
> > the catch handler (similar in concept to win32 seh) but currently all it
> > really can do is make a decision to continue searching or execute the
> > handler. All a type filter can do is execute the handler or keep
> > searching -
> > more complex decision making would be hard to achieve.
>
> It doesn't actually need to decide to resume. If you write a given filter
> with a handler that will do the resume, by deciding to execute the handler
> it is choosing to resume. You in effect create one handler that chooses
> resume or continue searching, while others chose execute handling code or
> continue searching.

We are talking apples and something else.

>
>
> At the IL level, there is no apparent restrictions on what you can do in a
> user filter. VB has a fair amount of restriction on a language level
> however, as I think it only allows a single statement(which can be a
method
> call).
>

Agreed. That's what I said. VB only allows simple expressions within the
When clause; the IL does not impose this restriction.



Relevant Pages

  • Re: CLI Exception Handling
    ... It is practically quite difficult to determine (in the handler block) from which IL instruction the exception was thrown. ... >> really can do is make a decision to continue searching or execute the ...
    (microsoft.public.dotnet.framework.clr)
  • Re: My lesson for today
    ... > or by exception, and in that image if ensure was nested inside exception ... > handler, it would surely be executed before exception handler. ... handler can't be made entirely free(some code always has to execute even if ...
    (comp.lang.smalltalk.dolphin)
  • Re: CLI Exception Handling
    ... > an exception occurs. ... You would have to use a filter to ensure that the exceptoin ... > could make the decision whether to resume, continue searching, or execute ... All a type filter can do is execute the handler or keep ...
    (microsoft.public.dotnet.framework.clr)
  • Re: CLI Exception Handling
    ... an exception occurs. ... The only way that section of the spec makes sense is that a user filter ... could make the decision whether to resume, continue searching, or execute ... the catch handler but currently all it ...
    (microsoft.public.dotnet.framework.clr)
  • Re: System.Security.SecurityException was unhandled
    ... The exception gave you the CLSID. ... the first thing to check might be whether the COM server ... assembly actually has the permission in question. ... When I execute the application I received and error message. ...
    (microsoft.public.dotnet.security)