| Start |
|---|
| Catching and rethrowing caught exceptions When you want to catch an exception and do something, but you can't continue execution of the current block of code because of the exception, you may want to rethrow the exception to the next exception handler in the call stack. There are good ways and bad ways to do this. You can filter by exception type and even by exception properties (new in C# 6.0, a bit longer available in VB.NET (citation needed)): |
| Using a finally block The It can be utilized to free or clean up resources acquired in the |
| Exception Filters Since C# 6.0 exceptions can be filtered using the This is similar to using a simple Example The same info can be found in the C# 6.0 Features (opens new window) here: Exception filters (opens new window) |
| Rethrowing an exception within a catch block Within a A common anti-pattern is to instead In general using |
| Throwing an exception from a different method while preserving its information Occasionally you'd want to catch an exception and throw it from a different thread or method while preserving the original exception stack. This can be done with |
| Catching an exception Code can and should throw exceptions in exceptional circumstances. Examples of this include:
The caller can handle these exceptions by "catching" them, and should only do so when:
It should be noted that choosing not to catch an exception is perfectly valid if the intention is for it to be handled at a higher level. Catching an exception is done by wrapping the potentially-throwing code in a RemarksRelated: |
Read Article
https://develop.horje.com/learn/1434/reference