从土司catch语句显示错误信息 [英] Displaying error messages from catch statements with toast

查看:162
本文介绍了从土司catch语句显示错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的catch语句在我的Andr​​oid应用程序,我想通过显示敬酒任何错误信息,我能做到这一点?

I have the following catch statement in my Android application and I would like to display any error messages via toast, can I do that?

catch (Exception e) 
{
    //Helper.displayExceptionMessage(this, e.getMessage());
    Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    e.printStackTrace();
}

public static void displayExceptionMessage(Context context, String msg)
{
    Toast.makeText(context, msg , Toast.LENGTH_LONG).show();
}

我也试图让一个辅助类,以显示消息,但我不知道如何解决帮手。

I’ve also tried to make a helper class to display the message but I have no idea how to resolve "Helper".

推荐答案

谢谢你们,

e.getMessage()的伎俩,

e.getMessage() did the trick,

我做了这个样子,

{
    ...    
    catch (Exception e) 
    {       
        e.printStackTrace();
        displayExceptionMessage(e.getMessage());
    }       
} 

public void displayExceptionMessage(String msg)
{
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}

这样我可以用它来测试在整个活动我猜。我不知道它可能是矫枉过正!

That way I can use it for testing throughout the whole activity I Guess. I don't know it could be overkill!!!

干杯,

麦克。

这篇关于从土司catch语句显示错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆