Since we now know a bit about C## classes, we can learn how to write code that handles unexpected situations and errors. This process is called exception handling, and is a part of all but the most basic C## programs.

Let’s learn about exceptions and how C## allows us to handle them!

An exception is an unexpected error that happens while a C## program is running. The C## runtime will transform an exception into an instance of a class, and we can use that instance to try to debug why the error happened.

All instances of an exception in C## must inherit from the class System.Exception. When an exception is encountered while a program is running, we say it has been thrown.

C## includes a huge variety of built-in exception classes. For example, if we attempt to divide by zero, an instance of System.DivideByZeroException will be thrown.

#c# in simple terms #c++ #c

C# in Simple Terms - Exceptions and Exception Handling
1.10 GEEK