my .NET application calls method of object that located out of assembly boundaries. When this method has thrown exception i’ve catched COMException.
Exception contains special code in ErrorCode field, for example -123.
try
{
// call outside object
}
catch(COMException e)
{
// e.ErrorCode == -123;
}
Is it posible to define exception class that will be thrown instead of COMException?
eg
[ErrorCode of external error = -123]
public class MyException : Exception;
and rewrite above code
try
{
// call outside object
}
catch(MyException e)
{
//…
}
“Is it posible to define exception class that will be thrown instead of COMException?”
No, but you could catch the COMException, wrap it in a custom exception class, and rethrow it.