1

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,

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

"Execution cannot be resumed at the location of the exception, except with a filter handler." from 12.4.2.5 Overview of exception handling.
@tgiphil sure, but the only specified return values for filter/endfilter are continue search and execute handler, as said. Now, if you returned -1 (or 0xffffffff), it might work the same as SEH; see msdn.microsoft.com/en-us/library/windows/desktop/…
2

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.

Comments

2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.