Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:56:33+00:00 2026-05-17T02:56:33+00:00

I have written my own Exception (MyException) and implemented Logging and showing Error Messages

  • 0

I have written my own Exception (MyException) and implemented Logging and showing Error Messages in Form of Toasts. Here is the shortform of it…

public class MyException extends Exception {

   public MyException(String msg) {
      Looper.prepare();
       Toast.makeText(Controller.getInstance().getApplicationContext(), msg , Toast.LENGTH_LONG).show();
       //Looper.loop();
       Looper.myLooper().quit();
   }
}

Everything was fine until I now implemented Threads where Exceptions are being thrown and caught.

You probably already have seen, that I played with the Looper Class, but honestly I don’t know how to make it work. Is that the right approach? You also can see that I already store a reference of the ApplicationContext in my Controller. Shall I do it with the ActivityContext as well and than make the Toast from this ActivityContext? (But I heard that this is not a good practice in terms of performance)

Update

Is this the way I should go, when an Exception is being caught in a Thread in an Activ ity?

private Runnable exceptionCatchingThread   = new Runnable() {
          @Override
          public void run() {
           try { 
                throw new Exception();
           } catch (Exception e) {
              this.e = e;
              runOnUiThread(handleThreadExceptions); }
           }
    }

private Runnable  handleThreadExceptions  = new Runnable() {
             @Override
              public void run() {
               //Show toast or call the general ExceptionHandler, 
               //which is doing logging and stuff
                Helper.handleException(e);
               }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:56:33+00:00Added an answer on May 17, 2026 at 2:56 am

    An Exception should be used to notify the caller that a problem occurred. It is the caller’s responsibility to do something with that notification, log, toasts, etc. You should not do any of that in the Exception class itself.

    You could create a helper method to be called when you catch an exception that does the toasting, etc. If you want to do this from multiple activities, you could create a util function where you pass in the context.

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

    and in your activity:

    try {
      // something that causes Exception
    } catch (MyException e) {
      Helper.displayExceptionMessage(this, e.getMessage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET application that we've written our own logging module for. My
I have written my own function, which in C would be declared like this,
I have written a java class where if a method throws an exception, an
I have written my own linked list implementation in C, and it works fine
I have written a mvc that uses nservicebus to publish messages. This works fine
I have written my own assertion debug. #define ASSERT_EQUALS(a,b) \ do { \ if
A lot of the code base methods my peers have written perform their own
I am developing an Android app. I have written my own code for back
I have written a windows service. The windows service has it's own namespace, obviously.
I have written an AIR Application that downloads videos and documents from a server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.