这更像是一种验证。
在 Oracle/Java 教程页面上,例如 this , 我一直看到 catch 旁边的“specify”就好像它是另一个语句 在异常处理中具有一些功能。
据我所知,“catch or specify”中的“specify`指的是 使用 throws 的检查异常的强制规范 在方法声明中,除非它被捕获和处理。 (未经检查的方法 也可以很好地指定,但在这种情况下不是强制性的。)
然而,这并没有固定在任何这些页面中,“指定”的格式就像它是一个 关键字虽然它isn't .
我是不是漏掉了什么?
最佳答案
据我所知,你没有遗漏任何东西。 specify
表示方法声明。也许他们使用代码标记来清楚地区分两者是等效的代码方法?也可能是一个简单的错误。
Why did the designers decide to force a method to specify all uncaught checked exceptions that can be thrown within its scope? Any Exception that can be thrown by a method is part of the method's public programming interface.
关于java - Java异常处理中的"specify",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18553411/