这几天一直在努力学习java,但是对Throws exception 很迷茫。此语句是否正确?:方法签名中的抛出会导致异常(或某些异常)抛出到调用此方法的另一个方法。调用方方法有 try/catch 来处理抛出的异常。
提前致谢。 法罗克
最佳答案
两种说法都不正确。
Throws in method signature causes an exception (or some exceptions) throw to another method that is calling this method
声明一个方法抛出
一个异常只是表明它可能抛出异常,而不是它确实抛出异常。
and caller method has try/catch to handle thrown exception.
调用者可以声明它抛出相同的异常,而不是尝试/捕获,因此异常会传播到该方法的调用者。
关于java - 在java中抛出规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29366895/