views:

128

answers:

3

Hi all,

Is it possible that using C# to do some exception handling with filter function and continue execution at the point where the exception occurred like C++ does?

Thanks,

+1  A: 

That sounds like VB's On Error Goto X/Resume Next pattern. If so, then no.

VB.NET allows it, but mainly for backwards compatibility. In .NET is is such a gross hack that and I've never seen anyone actually use it.

Jonathan Allen
+2  A: 

It's not possible.

.NET has an exception filtering mechanism, but it's not exposed through the C# language. Also, I don't believe it allows you to resume execution at the point where the exception occurred. It's more for deciding whether or not to catch an exception based on more than just the type of the exception.

Brannon
+2  A: 

The CLR supports exception filters of two-pass exception dispatch via the filter / endfilter IL clause, but the low-level instructions that directly implement it are not supported by the C# compiler.

Also, the only two return values from the clause that are supported are 0 and 1, which refer to exception_continue_search and exception_execute_handler respectively. So, resumption of execution at the point of the exception is not an option.

Barry Kelly