Java 我该如何解决“不能抛出 SomeException 类型的异常;异常类型必须是 Throwable' 的子类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27277008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I fix 'No exception of type SomeException can be thrown; an exception type must be a subclass of Throwable'
提问by user3535807
I have java webstart app and want to use app API for testing purposes. So I get required (as I assumed) library from webserver and install it to maven repository. And all is fine except custom exception which received
我有 java webstart 应用程序并想使用应用程序 API 进行测试。所以我从网络服务器获得了必需的(如我所假设的)库并将其安装到 Maven 存储库中。一切都很好,除了收到的自定义异常
No exception of type
SomeException
can be thrown; an exception type must be a subclass ofThrowable
SomeException
不能抛出任何类型的异常;异常类型必须是Throwable
As I understand from similar topics - some jar library is missing, is there some way to know which one? or maybe there is other way to fix this? (of course I can install all jars which used for app, but there are over 90 jar's).
正如我从类似主题中了解到的那样 - 缺少一些 jar 库,有什么方法可以知道是哪一个?或者也许有其他方法可以解决这个问题?(当然,我可以安装用于应用程序的所有 jar,但有 90 多个 jar)。
采纳答案by user3535807
I used JadClipse Eclipse plug-in for decompiling my jar and found that my SomeException extends FaultInfoException
(org.codehaus.xfire.fault.FaultInfoException),and then added xfire-all dependency to my pom.xml
我用JadClipse Eclipse插件反编译我的jar,发现我的SomeException extends FaultInfoException
(org.codehaus.xfire.fault.FaultInfoException),然后在我的pom.xml中添加了xfire-all依赖
回答by fge
If you want to define a custom exception, it MUST subclass Throwable
; but in practice you'll never subclass this directly. Subclass either of:
如果你想定义一个自定义异常,它必须是子类Throwable
;但在实践中,您永远不会直接将其子类化。子类:
Exception
if you want to create a checkedexception class;RuntimeException
if you want to create an uncheckedexception class.
Exception
如果你想创建一个检查异常类;RuntimeException
如果你想创建一个未经检查的异常类。
You may also want to subclass another exception already defined by the JDK, which defines a good number of exceptions which may fit what you want to "say" with your exception.
您可能还想对 JDK 已经定义的另一个异常进行子类化,它定义了大量的异常,这些异常可能适合您想对异常“说”的内容。