Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying error messages from catch statements with toast

Tags:

java

android

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".


1 Answers

Thanks guys,

e.getMessage() did the trick,

I did it like this,

{
    ...    
    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!!!

Cheers,

Mike.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!