Order catch blocks when try to handle an exception

前端 未结 5 1244
你的背包
你的背包 2020-12-19 14:05
try
{
    // throws IOException
}
catch(Exception e)
{
}
catch(IOException e)
{
}

when try block throws IOException, it wi

5条回答
  •  长情又很酷
    2020-12-19 14:23

    The reason is that IOException derives from Exception, so IOException actually is an Exception ("is-a") and therefore the first catch handler matches and is being entered.

提交回复
热议问题