Handling Exceptions in C# - When to catch them, where to catch them, and how to catch them

Published: 23 February 2018
on channel: IAmTimCorey
172,426
3.4k

Handling exceptions is about more than just putting try/catch blocks in your code. Where you put them is very important. It is also important to know when not to put a try/catch in your code.

This video covers the best practices of exception handling as well as how to rethrow exceptions, create new exceptions, and capture specific exceptions.

Newsletter signup (with exclusive discounts): https://signup.iamtimcorey.com/ (your email will be kept safe and you will not be spammed).
Source Code: https://leadmagnets.app/?Resource=Exc...

0:00 - Intro
0:39 - building a demo console application
9:49 - crashing the application
11:13 - "try-catch" and how NOT to use it
15:00 - continuing with the exception & showing exception information to the user (15:57 )
17:24 - more useful information: StackTrace
20:31 - "try-catch": best place to put it and why
27:23 - hanging logic demonstration
30:31 - the "finally" code block and "throw" statement. Passing exception up the stack (to UI)
38:08 - common misconceptions and mistakes
40:25 - creating new exception without losing the original StackTrace info
45:36 - recap
47:05 - advanced exception handling
53:09 - summary and tips on value capturing and handling exceptions


Watch video Handling Exceptions in C# - When to catch them, where to catch them, and how to catch them online, duration hours minute second in high quality that is uploaded to the channel IAmTimCorey 23 February 2018. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 172,426 times and liked it 3.4 thousand visitors.