Reputation: 5884
What exception should I throw if creating com object fails (in my own class instance constructor)? For example I want to create Excel.Application object. If it fails, I want to throw specific Exception with inner exception filled with COMException generated by Excel.Application constructor.
Upvotes: 0
Views: 80
Reputation: 7147
If you want to create your own class of exceptions you can, but you don't have to do that to wrap a new exception around an inner exception.
public class CustomException : Exception
{
}
public static void main()
{
try
{
//Code that instantiates COM object.
}
catch(Exception ex)
{
throw new CustomException("This is my message. I can put anything I want to, then pass the real exception as the inner exception", ex);
}
}
Upvotes: 1