title: My "MyException" which shows Toast causes trouble while thrown in threads. How should I reorganize Exception handling?
body: <p>I have written my own Exception (MyException) and implemented Logging and showing Error Messages in Form of Toasts. Here is the shortform of it...</p>
  
  <pre><code>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();
     }
  }
  </code></pre>
  
  <p>Everything was fine until I now implemented Threads where Exceptions are being thrown and caught.</p>
  
  <p>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) </p>
  
  <p><strong>Update</strong></p>
  
  <p>Is this the way I should go, when an Exception is being caught in a Thread in an Activ ity?</p>
  
  <pre><code>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);
                 }
  }
  </code></pre>