C# program to demonstrate the use of nested try and catch blocks
Program.cs
Output
kodingwindow@kw:~/csharp$ dotnet runFirst Exception: System.DivideByZeroException: Attempted to divide by zero. at Program.<Main>$(String[] args) in /home/kodingwindow/csharp/Program.cs:line 6 Second Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Program.<Main>$(String[] args) in /home/kodingwindow/csharp/Program.cs:line 13 kodingwindow@kw:~/csharp$
C# program to demonstrate the use of nested try and catch blocks
Program.cs
Output
kodingwindow@kw:~/csharp$ dotnet run Exception caught in the first nested catch block Exception caught in the third catch block kodingwindow@kw:~/csharp$
What Next?
C# program to demonstrate the use of finally blocks
C# program to handle the DivideByZeroException
C# program to handle the IndexOutOfRangeException
Advertisement