Handling specific exception types

suggest change
try
{
    /* code to open a file */
}
catch (System.IO.FileNotFoundException)
{
    /* code to handle the file being not found */
}
catch (System.IO.UnauthorizedAccessException)
{
    /* code to handle not being allowed access to the file */
}
catch (System.IO.IOException)
{
    /* code to handle IOException or a descendant other than the previous two */
}
catch (System.Exception)
{
    /* code to handle other errors */
}

Catch clauses are tested in order, and a clause matches derived types. Put the most specific types first and their ancestors later. Only one catch block runs.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents