Wednesday, October 30, 2013

Unable to catch automatically raised exception using derived exception class in catch block

That is because, if the file doesn't exist IOException is thrown but not DerivedException. Hence, your catch block will not catch the exception. To test it, you can manually throw an exception of type DerivedException.



public void OpenThisFile()
{
try
{
throw new DerivedException();
}
catch(DerivedException ex)
{
}
}



I hope this helps.




Please mark this post as answer if it solved your problem. Happy Programming!


No comments:

Post a Comment