Advertisement

Responsive Advertisement

Lesson: 6 Exception Handling I-Exception Overview,II - What is an Exception?, III. The Exception Class Hierarchy,IV-Structured Exception Handling


I-Exception Overview

The C# language's exception handling features help you deal with any unexpected or exceptional situations that occur when a program is running. Exception handling uses the try, catch, and finally keywords to try actions that may not succeed, to handle failures when you decide that it's reasonable to do so, and to clean up resources afterward. Exceptions can be generated by the common language runtime (CLR), by .NET or third-party libraries, or by application code. Exceptions are created by using the throw keyword.

II - What is an Exception?

An exception is defined as an event that occurs during the execution of a program that is unexpected by the program code. The actions to be performed in case of occurrence of an exception is not known to the program. In such a case, we create an exception object and call the exception handler code.




III. The Exception Class Hierarchy

The hierarchy of exceptions in C#
  • ArgumentException. ArgumentNullException. ArgumentOutOfRangeException.
  • DivideByZeroException.
  • IndexOutOfRangeException.
  • NullReferenceException.
  • RankException.
  • StackOverflowException.
  • IOException. EndOfStreamException. FileNotFoundException. FileLoadException.

IV-Structured Exception Handling

Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords: try, catch, finally, and throw. try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.



















Post a Comment

0 Comments