小编hd8*_*335的帖子

使用 Java 可选的 ifPresentOrElse 方法时无法抛出“已检查”异常

为什么在使用ifPresentOrElsejava Optional 方法时不能在 orElse 部分抛出已检查的异常?

例如:

dao.findBook(id).ifPresentOrElse(book -> {
    printingService.print(book, printerName);
    changeBookPrintDate(book.getId(), LocalDateTime.now());
}, () -> new BookNotFoundException());
Run Code Online (Sandbox Code Playgroud)

哪里BookNotFoundException是自定义异常扩展Exception类(检查异常)。

但是这段代码让编译器感到不安:

unreported exception com...exception.BookNotFoundException; must be caught or declared to be thrown
Run Code Online (Sandbox Code Playgroud)

(知道它已经在方法声明中抛出,并且用 try catch 包围这个块并不能解决编译问题)。

但是,如果我们BookNotFoundException要扩展RuntimeException(这是未经检查的),那么一切都完美无缺。

有谁知道为什么?

阻止在此 java 9 Optional 方法中抛出此类异常的原因是什么?

为什么我要让我的异常成为 RuntimeException 以使其工作,而它更应该被视为“自定义异常”而不是“运行时”?

这个问题解决了同样的问题,但对于 java 8 lambdas,所以我不知道这是否同样适用于 java 9 Optionals。

其他研究只能证实这是不可能的

任何的想法 ?

java exception optional java-9 java-11

4
推荐指数
2
解决办法
3708
查看次数

运行Axis2 Web服务客户端在客户端和服务器端生成错误

客户端错误是:

    0 [main] INFO org.ws.call.BankWSCallClass - callChequeCertificationWS...
702 [main] INFO org.ws.call.BankWSCallClass - callChequeVerificationWS... serviceCreated
702 [main] INFO org.ws.call.BankWSCallClass - callChequeVerificationWS... portCreated
Exception in thread "main" org.apache.axis2.AxisFault: Exception occurred while trying to invoke service method chequeCertification
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
    at org.ws.server.implementation.ChequeProcessingServiceStub.chequeCertification(ChequeProcessingServiceStub.java:911)
    at org.ws.call.BankWSCallClass.callChequeCertificationWS(BankWSCallClass.java:53)
    at org.ws.call.BankWSCallClass.main(BankWSCallClass.java:106)
Run Code Online (Sandbox Code Playgroud)

虽然服务器端错误是

    [#|2012-05-10T15:52:32.390+0300|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=79;_ThreadName=Thread-2;|[ERROR] Exception occurred while trying to invoke service method chequeCertification
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114) …
Run Code Online (Sandbox Code Playgroud)

java eclipse axis2 web-services

2
推荐指数
1
解决办法
1万
查看次数

无法在Glassfish上部署JAX-WS Web服务

我在使用Glassfish应用程序服务器运行JAX_WS Webservices时遇到问题.以前,我曾经使用Apache tomcat,它可以很好地工作.但是现在,有了Glassfish,这个问题阻止了应用程序的部署...请在下面查看:

2013-04-04T13:09:23.028+0300 com.sun.xml.ws.wspolicy.com.sun.xml.ws.api.policy.ModelTranslator
SEVERE: [failed to localize] WSP_0071_ERROR_MULTIPLE_ASSERTION_CREATORS_FOR_NAMESPACE(http://schemas.xmlsoap.org/ws/2004/08/addressing, com.sun.xml.ws.security.addressing.impl.policy.AddressingPolicyAssertionCreator, com.sun.xml.ws.addressing.impl.policy.AddressingPolicyAssertionCreator)
2013-04-04T13:09:23.028+0300 com.sun.xml.ws.wspolicy.jaxws.PolicyWSDLParserExtension
SEVERE: [failed to localize] WSP_0071_ERROR_MULTIPLE_ASSERTION_CREATORS_FOR_NAMESPACE(http://schemas.xmlsoap.org/ws/2004/08/addressing, com.sun.xml.ws.security.addressing.impl.policy.AddressingPolicyAssertionCreator, com.sun.xml.ws.addressing.impl.policy.AddressingPolicyAssertionCreator)
2013-04-04T13:09:23.028+0300 com.sun.xml.ws.wspolicy.jaxws.PolicyWSDLParserExtension
SEVERE: WSP1007: Policy exception occurred when finishing WSDL parsing.
com.sun.xml.ws.policy.PolicyException: [failed to localize] WSP_0071_ERROR_MULTIPLE_ASSERTION_CREATORS_FOR_NAMESPACE(http://schemas.xmlsoap.org/ws/2004/08/addressing, com.sun.xml.ws.security.addressing.impl.policy.AddressingPolicyAssertionCreator, com.sun.xml.ws.addressing.impl.policy.AddressingPolicyAssertionCreator)
    at com.sun.xml.ws.policy.sourcemodel.PolicyModelTranslator.<init>(PolicyModelTranslator.java:188)
    at com.sun.xml.ws.api.policy.ModelTranslator.<init>(ModelTranslator.java:85)
    at com.sun.xml.ws.api.policy.ModelTranslator.<clinit>(ModelTranslator.java:74)
    at com.sun.xml.ws.policy.jaxws.BuilderHandler.getPolicies(BuilderHandler.java:102)
    at com.sun.xml.ws.policy.jaxws.BuilderHandler.getPolicySubjects(BuilderHandler.java:110)
    at com.sun.xml.ws.policy.jaxws.BuilderHandlerEndpointScope.doPopulate(BuilderHandlerEndpointScope.java:72)
    at com.sun.xml.ws.policy.jaxws.BuilderHandler.populate(BuilderHandler.java:82)
    at com.sun.xml.ws.policy.jaxws.PolicyMapBuilder.getNewPolicyMap(PolicyMapBuilder.java:109)
    at com.sun.xml.ws.policy.jaxws.PolicyMapBuilder.getPolicyMap(PolicyMapBuilder.java:91)
    at com.sun.xml.ws.policy.jaxws.PolicyWSDLParserExtension.postFinished(PolicyWSDLParserExtension.java:960)
    at com.sun.xml.ws.wsdl.parser.DelegatingParserExtension.postFinished(DelegatingParserExtension.java:191)
    at com.sun.xml.ws.wsdl.parser.WSDLParserExtensionFacade.postFinished(WSDLParserExtensionFacade.java:338)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:234)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:191)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:160)
    at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:307)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:269)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:205)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:195)
    at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:112)
    at …
Run Code Online (Sandbox Code Playgroud)

java myeclipse web-services jax-ws glassfish-3

2
推荐指数
1
解决办法
2689
查看次数

无法使用化石 scm 提交

最近由于以下错误我无法提交:

$ fossil commit
$EDITOR './ci-comment-CEA221250987.txt'
Unsafe command string: $EDITOR './ci-comment-CEA221250987.txt'
              here ----^
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

这是化石问题还是我的配置中有一些胭脂.bashrc


我的化石版本是

$ fossil version
This is fossil version 2.12.1 [b98ce23d4f] 2020-08-20 13:27:04 UT
Run Code Online (Sandbox Code Playgroud)

并且$EDITOR

$ echo $EDITOR
vim
Run Code Online (Sandbox Code Playgroud)

version-control fossil

1
推荐指数
1
解决办法
75
查看次数

尝试在 VSCode 中创建新的 Maven 项目时出现“错误:在您的环境中找不到 JAVA_HOME”

我正在尝试通过VSCodeMaven for Java扩展生成一个 Maven 项目。

这是我的问题:在资源管理器中单击“创建新的 Maven 项目”后,选择快速启动选项,然后选择我想要工作的文件夹,我在终端中出现错误,如下所示:

Error: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Run Code Online (Sandbox Code Playgroud)

目前,我的JAVA_HOME系统变量设置为C:\Progra~1\Java\jdk1.8.0_271.

有关如何消除此错误的任何建议?我不确定这是否重要,但我JDK的安装在 C 驱动器上,我正尝试在 M 驱动器上创建一个项目。

谢谢!

java java-home maven visual-studio-code

0
推荐指数
1
解决办法
6404
查看次数