Skip to content

Instantly share code, notes, and snippets.

@ryanwebjackson
Created February 9, 2018 19:24
Show Gist options
  • Save ryanwebjackson/a7514f339b04bb0ce8c2c623064dddd3 to your computer and use it in GitHub Desktop.
Save ryanwebjackson/a7514f339b04bb0ce8c2c623064dddd3 to your computer and use it in GitHub Desktop.

Try/Finally does not catch an error! What is does is execute the finally block after throwing the error.
The only reason I could think to do this is the disposal of opened resources (this is the recommendation from Microsoft as well).

(https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/try-finally)

Personally, I don't see much of an advantage in this, as you might as well catch the exception and do any clean up in the catch block.
At that point finally would serve no purpose (as code execution would/will continue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment