I start a process with the default application for the file type, but if the user has deleted his default application, a Win32Exception is thrown. In addition there are other cases when a Win32Exception is thrown e.g. if the user has no rights to open the default application.
Now I'm looking for the best way to seperate between the exceptions.
How can i check which exception exactly is thrown? Is the only way to check it by its Exception message?
I'm catching it like this:
try
{
process.Start();
}
catch (Win32Exception exc)
{
//How to check which exception exactly is thrown?
return return string.Format("Process cannot be started", exc.Message)
}
This was mit first idea but i think there is a better way to accomplish this task:
catch (Win32Exception exc)
{
if(exc.Message == "Application not found")
{
//Do something
}
else if(exc.Message == "Another exception")
{
//Do something else
}
}
NativeErrorCode
property of the exception – Dulciedulcify