简体   繁体   English

安卓 具有几个try-catch块的onPostExecute

[英]Android. onPostExecute with several try-catch blocks

First of all, I have almost no experience in Java. 首先,我几乎没有Java经验。 I'm using AsyncTask to get some data from my server and in the onPostExecute method I need to use several try-catch blocks to manage the received data. 我正在使用AsyncTask从服务器中获取一些数据,在onPostExecute方法中,我需要使用几个try-catch块来管理接收到的数据。 If one of them fails (catch is executed) the app should stop execution and show a dialog. 如果其中之一失败(执行了catch),则应用程序应停止执行并显示一个对话框。 But when any catch block is executed, the following try-catch blocks are executed, and that's what I want to avoid. 但是,当执行任何catch块时,将执行以下try-catch块,这就是我要避免的事情。 I can't use return because onPostExecute returns void. 我不能使用return因为onPostExecute返回void。

So, what is the best way to manage this situation to achieve what I need? 那么,管理这种情况以实现我所需要的最佳方法是什么?

If a Method returns Void, you can use "return;" 如果Method返回Void,则可以使用“ return;”。 to exit the method. 退出方法。

So in the Catch block, Show the Dialogand Exit with return; 因此,在Catch块中,显示Dialogand Exit with return;

Elsewhere you can catch different exceptions in one try block. 在其他地方,您可以在一个try块中捕获不同的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM