如果需要,可以将throws子句添加到方法中。然后,您不必立即捕获已检查的方法。这样一来,您可以赶上
exceptions后面的内容(也许与other同时
exceptions)。
代码如下:
public void someMethode() throws SomeCheckedException { // pre}然后,
exceptions如果不想使用该方法处理它们,则可以处理。
为了捕获所有异常,您可能会抛出一些代码块:(这也会捕获
Exceptions您自己编写的代码)
try { // exceptional block of pre ... // ...} catch (Exception e){ // Deal with e as you please. //e may be any type of exception at all.}起作用的原因是因为它
Exception是所有异常的基类。因此,可能引发的任何异常都是
Exception(大写的“ E”)。
如果要处理自己的异常,只需
catch在通用异常之前添加一个块。
try{ }catch(MyOwnException me){}catch(Exception e){}


