How to extract that error code without having to depend on casting as seen in the code below? In the screenshot, Number is a property of object InnerException, yet it is not accessible.
try
{
// db call
}
catch (Exception exc)
{
// Works
var q = exc.InnerException as SqlException;
var ErrorCode = q.Number;
// Not possible
var err = exc.InnerException.Number;
}
Why is that not possible and is there an alternative? Also, where to find the documentation for the InnerException Number property?