kodingwindow@kw:~/csharp$ dotnet run
First 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
strings=null;intn=515,d=0,result=0;try{Console.WriteLine("Length: "+s.Length);}catch(InvalidOperationExceptione){Console.WriteLine("Exception caught in the first catch block");}catch(Exceptione1){try{result=n/d;}catch(DivideByZeroExceptione2){Console.WriteLine("Exception caught in the first nested catch block");}Console.WriteLine("Exception caught in the third catch block");}
Output
kodingwindow@kw:~/csharp$ dotnet run
Exception caught in the first nested catch block
Exception caught in the third catch block
kodingwindow@kw:~/csharp$
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?