简体   繁体   中英

Android exception handling, program halts

I'm trying to catch a login exception thrown by the class that readerAccount belongs to in the code below.

while(!readerAccount.isAuthenticated()) {
    try {
        readerAccount.login();
    } catch(AuthenticationException e) {
        cmDialog.show();
        Toast.makeText(this.mCtx, "login failed", Toast.LENGTH_SHORT).show();
        Log.w("Google Reader API","login failed");
        continue;
    }
}

However, the only part of the catch statement that happens is is the Log.w() function. I was under the impression that during a catch statement, you have the opportunity to recover from errors, but the program blacks out the screen altogether and the dialog is not displayed, nor is the Toast. What's going on here?

It is possible that the .login() call leads to changes of the other objects you use in the catch statement (specially when something goes wrong and that exception is thrown), or to the locking of resources related in some way with them, which might explain why the .show() and .makeTest(...) calls don't act the way you are expecting, inside the catch statement.

You might want to try printing attributes and information about the cmDialog object, before the try statement, and inside the catch statement, before the .show() call, to be able to compare and check if anything altered the object's state or the state of any of it's used resources.

I hope that helps.

i've got the answer to this. the code that should be run after the dialog is interacted with should always be placed in the onClickListener for the specific dialog being displayed. so the login() function should be called from within the onClickListener and if an unsuccessful login occurs, the dialog should be recalled until a successful login is made.

thanks anyway everyone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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