views:

295

answers:

2

I was reading this article on handling corrupted state exceptions and I came across something that puzzled me.

What is a fault clause?

See quote from article below:

An error condition can only pass from the function containing the unexpected condition to that function's caller. Exceptions have the power to pass the results of a function's execution out of the current function's scope to every frame up the stack until it reaches the frame that knows how to handle the unexpected condition. The CLR's exception system (called a two-pass exception system) delivers the exception to every predecessor on the thread's call stack, beginning with the caller and proceeding until some function says it will handle the exception (this is known as the first pass).

The exception system will then unwind the state of each frame on the call stack between where the exception is raised and where it will be handled (known as the second pass). As the stack unwinds, the CLR will run both finally clauses and fault clauses in each frame as it is unwound. Then, the catch clause in the handling frame is executed.

+5  A: 

According to this article:

Another example of a SEH clause not available in the C# language is the fault clause. It is similar to the finally clause except that it's only invoked when an exception has been thrown in the guarded block.

Another article confirms:

The fault exception handler is similar to the finally block except that it is invoked only if it’s associated try block is left as a result of an exception. After the fault handler has been given an opportunity to execute, the exception continues on its way in search or a handler that is willing to catch it.

Michael Myers
+1  A: 

The fault clause is a clause that is part of the CLI but not available in C#. It is very similar to a finally clause except it is only invoked when an exception was thrown in the try block (whereas a finally block executes regardless of whether or not an exception was thrown).

Andrew Hare