Answers for "how to get exception number and other details in c#"

C#
2

get type of exception c#

try
{
    // do something here
}
catch(Exception ex)
{
	// will print System.NullReferenceException for example
    Console.WriteLine(ex.GetType().ToString());
}
Posted by: Guest on July-01-2021
0

how to get error code from exception in c#

try {
	// some operation causing an exception
}
catch (SqlException e) {
	if (e.ErrorCode == 0x80131904)
      	// ...
		return null;
	throw;
}
Posted by: Guest on March-25-2021

Code answers related to "how to get exception number and other details in c#"

C# Answers by Framework

Browse Popular Code Answers by Language