Order catch blocks when try to handle an exception

前端 未结 5 1250
你的背包
你的背包 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:20

    IOException inherits from Exception. All Exceptions do. When you catch Exception first, you will catch all exceptions (including IOException). Make sure that your catch(Exception e) is the last catch in the list otherwise all other exception handling will be effectively ignored.

提交回复
热议问题