Vb Net Innerexception

/ Comments off
  1. Vb.net Check Innerexception
  2. Vb.net Innerexception Null

Gets a read-only collection of the Exception instances that caused the current exception. Gets a read-only collection of the Exception instances that caused the current exception.

Back to: C#.NET Tutorials For Beginners and Professionals

Inner Exception in C# with an Example

Vb.net Check Innerexception

In this article, I am going to discuss the Inner Exception in C# with examples. Please read our previous article before proceeding to this article where we discussed how to create a Custom Exception in C# with examples. At the end of this article, you will understand what is Inner Exception and its need in C#.

What is Inner Exception in C#?

The Inner Exception in C# is a property of an exception class. When there is a series of exceptions, then the most current exception obtains the previous exception details in the InnerException property. In order words, we can say that the InnerException property returns the original exception that caused the current exception. If this is not clear at the moment, then don’t worry we will discuss this with examples.

Inner Exception Example in C#:

Let us say we have an exception inside a try block which is throwing DivideByZeroExceptionand the catch block catches that exception and then tries to write that exception it to a file. However, if the file path is not found, then the catch block is also going to throw FileNotFoundException.

Let’s say the outside try block catches this FileNotFoundException exception, but how about the actual DivideByZeroExceptionthat was thrown? Is it lost? Dragon ball z ultimate tenkaichi key. No, the InnerException property of the Exception class contains the actual exception.

Example:

Let us understand the Inner Exception with an example. In order to see the inner exception, we have to make this program cause an exception to fail. To do that we have 3 options

  • Enter a Character instead of a number (Causes Format Exception)
  • Or Enter a very big number that an integer cannot hold (Causes Over Flow Exception)
  • Vb.net ex.innerexception.message
  • Or Enter Zero for Second Number (Causes Divide By Zero Exception)
  • Vb Net Innerexception

    When you run the above program it will give us the following output.

    Inner

    Vb.net Innerexception Null

    In the next article, I am going to discuss theException Handling Abusein C#. Here, in this article, I try to explain the Inner Exception in C# with examples. I would like to have your feedback. Please post your feedback, question, or comments about this article.