kodingwindow@kw:~/csharp$ dotnet run
Unhandled exception. System.ArgumentException: Object must be of type String.
at System.String.CompareTo(Object value)
at Program.<Main>$(String[] args) in /home/kodingwindow/csharp/Program.cs:line 3
kodingwindow@kw:~/csharp$
C# program to handle the ArgumentException
Program.cs
inti=0;strings="Hello, World!";try{Console.WriteLine(s.CompareTo(i));}catch(ArgumentException){Console.WriteLine("Something went wrong...");}
Output
kodingwindow@kw:~/csharp$ dotnet run
Something went wrong...
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.