C# NullReferenceException
Program.cs
Output
kodingwindow@kw:~/csharp$ dotnet runUnhandled 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 2 kodingwindow@kw:~/csharp$
C# program to demonstrate the use of try and catch blocks
Program.cs
Output
kodingwindow@kw:~/csharp$ dotnet run String is null, hence, unable to find the length. kodingwindow@kw:~/csharp$
C# program to demonstrate the use of try with multiple catch blocks
Program.cs
Output
kodingwindow@kw:~/csharp$ dotnet run Exception caught in the second catch block kodingwindow@kw:~/csharp$
What Next?
C# program to catch all the exceptions using Exception class
C# program to demonstrate the use of nested try and catch blocks
C# program to demonstrate the use of finally blocks
Advertisement