处理异常后如何恢复代码操作?

Wai*_* II 1 java

问:如何在处理异常后恢复代码操作?我现在使用try和catch.

Try
{
    Process url and render the text and save contents to text file.
}Catch(Exception ex)
}
Run Code Online (Sandbox Code Playgroud)

有些网址坏了,所以我如何跳过破碎的网址并继续使用其他网址?

Mat*_*Mat 8

取决于您如何迭代您的网址.例如:

for (URL url: urllist) {
  try {
    // Process **one** url
  } catch (Exception ex) {
    // handle the exception
  }
}
Run Code Online (Sandbox Code Playgroud)

这将处理列表中的所有URL,即使某些处理引发异常.