Implementing Exception Handling

Exception handling helps developers structure their programs in a way that helps them handle both expected and unexpected scenarios. Often, application logic may throw some form of unhandled exception, for example, a code block trying to write to a file on a system that ends up with a file with a use exception. Such scenarios can be handled if proper exception handling is in place.

Exception handling uses the try, catch, and finally keywords to allow us to write code that may not succeed and can be handled when required, as well as to help us clean up resources once the try block has been executed. These exceptions can be thrown by CLR, .NET Framework, or by external libraries that are used in your code.

In this chapter, we will try to understand how we can use, create, and throw exceptions by looking at the following topics:

  • Exceptions and handling exceptions in code
  • Compiler-generated exceptions
  • Custom exceptions

After reading this chapter, you will be able to structure an application program and handle all sorts of exceptions that may be thrown from your application logic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.255.36