是否可以在异常之前读取答案?
我正在开发一个项目,其中 Android 应用程序与 PHP 服务器(WAMP)进行通信,其中实现了一些方法。我们使用 XMLRPC 来处理客户端对服务器方法的调用。无论如何,即使一切都发生得很好,当 java 尝试读取答案时会抛出异常。所以我想知道在java抛出异常之前是否有任何方法可以读取或保存服务器的响应(这并不真正相关)?
预先感谢您的帮助!
I'm working on a project where an android application is communicating with a PHP server (WAMP) where some methods are implemented. We're using XMLRPC to handle client calls to server's methods. Anyway, even though everything happens fine, an exception is thrown when java tries to read the answer. So I would like to know if there is any way to read or save the server's response before java throws the exception (which is not really relevant) ?
Thanks in advance for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常的方法是在代码中捕获并处理此未经检查的异常。如果你没有抓住它,就会导致应用程序停止。
将导致异常的代码段包装到 try/catch 语句中。这应该允许您的申请继续,并且您应该能够保留和处理响应。
The usual approach is to catch and handle this unchecked exception in your code. If you don't catch it, it will cause the application to stop.
Wrap the piece of code that causes the exception into a try/catch statement. This should allow you application to continue and you should be able to keep and process the response.
我已经设置了一个 try/catch 语句,如您所见:
storeData 方法应该返回一个 int。但当我遇到异常时,我看不到该响应。
这是我收到的错误:[Fatal Error] :1:1: Content is not allowed in prolog.
我认为这是由于 xml 响应中存在一些错误字符,所以这就是我想要的原因得到这个回应!
I do already set up a try/catch statement as you can see :
The storeData method is supposed to return an int. But as I get an exception, I can't see that response.
This is the error I get : [Fatal Error] :1:1: Content is not allowed in prolog.
I assume it's due to some bad characters in the xml response so that's why I'd like to get this response !