Catching all possible exceptions in gui thread

Hi,
I have such a problem: I am developing Swing app and sometimes it crashes by throwing an Exception which I don't catch. The effect is that this exception prints stack trace on System.err but user is not notified and wonders what is happening... I would prefer to show custom ErrorDialog with stacktrace.
I am searching for simple and effective way to catch every possible exception thrown from within any library. I think of a few ways from which everyone has some disadvantages.
The ideal way would be replacing AWT event queue dispatcher so I could process every GUI event inside try { } catch (Exception e) {} block. That would be a good place to catch all exceptions. Unfortunately I don't know if it is possible.
For now I am trying such a solution:
I start background thread together with main app. Then I redirect System.err and System.out streams to PipedStream connected to this background thread. This thread can analyze anything that is going to System.err and maybe recognize potential exception stacktraces. Then it can notify main thread of an exception. But it is not ideal as I have to parse the stream and it can always be not ideal in exception recognition. And the code is quite costly.
Do you have any ideas, had similar problems?

But how can I cause GUI thread to run in my thread
group? As I suppose GUI thread is started by JVM and
is something separate from my code - I can get a
reference to GUI thread but don't know how to
manipulate or replace it...One alternative is to completely separate the GUI code from your code.
Your code, which is wrapped in appropriate try/catch blocks, runs on its own thread and does its own processing. When it's done with that processing, it queues the results on the event thread for display. If an exception occurs during your processing, then you queue something that notifies the GUI.
The simplest way to implement this is to spawn a new thread for each operation. The Runnable that you give to that thread looks like the following:
public MyOperationClass implements Runnable
    public void run()
        try
            // do your exception-generating code here
            SwingUtilities.invokeLater( new MyGUIUpdateClass(param1, param2));
        catch (Exception e)
            SwingUtilities.invokeLater(new MyExceptionReporter(e));
}This is only a bare-bones solution (and hasn't been compiled). Since it separates the GUI from actual processing, you'll probably want to display a wait cursor while the processing thread is doing its thing. You'll probably end up implementing a class that implements this pattern. You may also want to create a producer-consumer thread, so that the user won't invoke, say, a dozen different operations at once.
However, this sort of code is absolutely essential to Swing programming. Most apps do extensive non-GUI processing, such as database queries. If you run such queries in the GUI thread, your GUI will freeze.
Sun has named this pattern "SwingWorker", although I don't think they've fleshed it out very fully: http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

Similar Messages

  • Catch all uncaught exceptions in GUI

    Is there a way to catch any uncaught exceptions within my GUI so that I can do some special handling instead of it being echoed to the console?

    It's actually an AWT class that's catching the errors: EventDispatchThread. There is a way to override that mechanism, but it's unsupported, and the only place it's documented is in the source code of that class. Here's an example.
    public class MyApp
      public static void main(String[] args)
        System.setProperty("sun.awt.exception.handler",
                           "MyApp$EDTErrorHandler");
        // create and show the GUI
       * This class will be instantiated by the
       * EventDispatchThread the first time it
       * encounters an exception or error.
      public static class EDTErrorHandler
         * This method is invoked by the AWT event
         * dispatch mechanism when an unexpected
         * exception or error is thrown during
         * event dispatching.
        public void handle(Throwable t)
          // handle the error
    }

  • Catcherror event "catch all system exceptions" is not catching subLanguageExecutionFault

    catcherror event "catch all system exceptions" is not catching subLanguageExecutionFault in BPM process

    hi rani,
    thanks for the response
    i supply all the connection details(gatewayhost, gatewayservice, programid, clinet, systemnumber, applicationhost, userid, password etc.) to the program which extends "JCoIDoc.Server".
    the program is taking care of all the connection establishment details.but still m facing the same problem.
    i have also confirmed that the user is a communication user, not a dialogue user.
    thanks
    pavan

  • Catching all the exceptions at once

    Can we catch all exception and throw it all at once?
    Here's what i want to do..
    Say i have a class in which i have around 4 sql statements
    which i'm putting it in a try. I do not want to throw execptions one by one.
    instead
    try{
    some statements
    catch{
    goto Error -->
    catch{
    goto Error -->
    Error:
    Show all the statements here..
    I do not want to do this manually..is there already an exists9ing class or something that we need to implement. Please reply
    Tahnks,
    Anjana

    Just catch Exception. its the motherclass of all exceptions.
    put everything in one big try/catch.

  • Best Practice: JavaFX pattern for "Catching all Exceptions"

    Hi,
    what is on the current JavaFX Standard the best way to catch all Exceptions (centralized) within my JavaFX application...
    I read thread outside this Oracle Forum who recommend following:
    1. Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());
    --> catch all runtime exceptions
    2. http://stackoverflow.com/questions/12318861/javafx-2-catching-all-runtime-exceptions
    --> Implementing some source code who wrap the current GUI thread...
    3. I read something like:
    "JavaFX exception handling is almost identical to that in Java, apart from the fact that checked exceptions are handled in the same way as unchecked exceptions. This is good news for most Java programmers moving to JavaFX because you are no longer obliged to catch and handle exceptions."
    Sounds very good! But where/how can I do this ???
    Edited by: wschele on 19.02.2013 04:58
    Edited by: wschele on 19.02.2013 05:16

    No recommendation whats the best way to do it?
    Catching each Exception in different layers is boring ! :-(

  • Trying to catch all exceptions...

    Hi, developers!
    I am trying to develop the best code, that can catch all the exceptions, in the best possible way, and whenever as possible it must register in a log with informations about the exception occurred.
    I need your suggestions. See the code below:
    MyClass()
      throws IOException, MyException {
      Throwable objThrowable1 = null;
      try {
        doSomething();
      } catch(MyException e) {
        objThrowable1 = e;
        throw e;
      } catch(IOException e) {
        objThrowable1 = e;
        throw e;
      } catch(RuntimeException e) {
        objThrowable1 = e;
        throw e;
      } catch(Exception e) {
        objThrowable1 = e;
        throw new Exception("Some Exception occurred.", e);
      } catch(Error e) {
        objThrowable1 = e;
        throw e;
      } finally {
        if (objThrowable1 != null) {
          Throwable objThrowable2 = null;
          try {
            log.fatal(objThrowable1);
            objThrowable1.printStackTrace();
          } catch(RuntimeException e) {
            objThrowable2 = e;
            throw e;
          } catch(Exception e) {
            objThrowable2 = e;
            throw new Exception("Some Exception occurred while logging.", e);
          } catch(Error e) {
            objThrowable2 = e;
            throw e;
          } finally {
            if (objThrowable2 != null) {
              objThrowable2.printStackTrace();
    }It is the constructor of MyClass, and it might throw IOException or MyException.
    Now some questions:
    1) Do you think I exaggerated and wrote a lot of code, more than sufficient?
    2) I wrote all this code because I think it�s a good idea throwing exceptions, especially RuntimeException and Error. The Virtual Machine must know how to handle the situation when some exception occurs. But I want to register a log of the exception, too, whenever as possible. In my opinion, the only way to advise the Virtual Machine that some exception occurred is throwing this exception. Do you agree? Do I really need to worry about it?
    Thanks in advance!

    Hi, developers!
    I am trying to develop the best code, that can catch
    all the exceptions, in the best possible way,Define "best possible way". I don't think what you're proposing is even close, by any measure.
    You should only catch exceptions that you intend to handle. If there's no way for your class to handle the exception, it should bubble it up to the class that will. Catching and rethrowing like that seems a total waste to me.
    I need your suggestions. See the code below:I'd suggest that this is an ugly mess. I would not go this way.
    I have no idea whatsoever about that finally block. That should be for cleanup. What are you doing there?
    MyClass()
    throws IOException, MyException {
    Throwable objThrowable1 = null;
    try {
    doSomething();
    } catch(MyException e) {
    objThrowable1 = e;
    throw e;
    } catch(IOException e) {
    objThrowable1 = e;
    throw e;
    } catch(RuntimeException e) {
    objThrowable1 = e;
    throw e;
    } catch(Exception e) {
    objThrowable1 = e;
    throw new Exception("Some Exception occurred.",
    d.", e);
    } catch(Error e) {
    objThrowable1 = e;
    throw e;
    } finally {
    if (objThrowable1 != null) {
    Throwable objThrowable2 = null;
    try {
    log.fatal(objThrowable1);
    objThrowable1.printStackTrace();
    } catch(RuntimeException e) {
    objThrowable2 = e;
    throw e;
    } catch(Exception e) {
    objThrowable2 = e;
    throw new Exception("Some Exception occurred
    occurred while logging.", e);
    } catch(Error e) {
    objThrowable2 = e;
    throw e;
    } finally {
    if (objThrowable2 != null) {
    objThrowable2.printStackTrace();
    }It is the constructor of MyClass, and it might
    throw IOException or MyException.
    Now some questions:
    1) Do you think I exaggerated and wrote a lot of
    code, more than sufficient?
    2) I wrote all this code because I think it�s a good
    idea throwing exceptions, especially
    RuntimeException and Error. The Virtual
    Machine must know how to handle the situation when
    some exception occurs. But I want to register a log
    of the exception, too, whenever as possible. In my
    opinion, the only way to advise the Virtual Machine
    that some exception occurred is throwing this
    exception. Do you agree? Do I really need to worry
    about it?
    Thanks in advance!Cath t

  • Find all unchecked exceptions thrown by method?

    Dear all,
    I am writing critical code that must be correct. Thus, I wish to know that I have not overlooked any important unchecked exceptions. I am aware that the distinction between unchecked and checked exceptions is controversial, and I know the difference between these types of exceptions.
    I would like to see for each function a list of all possible exceptions a method can throw. Preferably I would like a tool to do this for me, but I would write something myself if there is a reasonably simple way to do it.
    More precisely, I would like to be able to define the set of "unchecked" exceptions myself, e.g., I would put down NullPointerException as "unchecked", but I would let IOException be checked (in my particular application, not in general). In general, this would however be a very nice language feature that could perhaps be a compromise in the (un)checked exceptions-controversy. Each programmer could define an "unchecked"-filter. Perhaps it would best be viewed as a kind of lint.
    In any case, I have not found any tool, and it seems I can not do it myself with reflection, since it only gives access to declared exceptions, i.e., if the JDK-programmer decided not to put IOException in the signature of a method, then reflection can not see that the method may throw such an exception.
    Does anybody know how to do this?

    Douglas1024 wrote:
    Thank you for your time, but I am well aware how one uses exceptions in normal code.
    From an abstract point of view exceptions are simply a form of outputs from a method. Thus, if the goal is to write correct and easily verifiable code, in contrast to the vast majority of code that simply works reasonably, it is quite meaningful to know exactly what kinds of exceptions are thrown by a method and when.
    Please note my correction regarding IOException.Millions upon millions of lines of correct code have been written following these standard java exception principles. The notion that you can write "better" code by detailing every single unchecked exception that could possibly be thrown is ludicrous. In fact by handling unchecked exceptions you will in all likelihood do more harm than good, hence why they are unchecked in the first place.

  • Catching System.loadLibrary exceptions

    I looked at the JNI book examples, and none does that. So i conclude that it is better to let that exception propagate up the stack. It makes sense because otherwise class behavior would be undefined. If you have evidence to the contrary, please speak up.
    Thanks.
    chap2/HelloWorld/HelloWorld.java- static {
    chap2/HelloWorld/HelloWorld.java: System.loadLibrary("HelloWorld");
    chap2/HelloWorld/HelloWorld.java- }
    chap2/HelloWorld/HelloWorld.java-}
    chap3/IntArray/IntArray.java- static {
    chap3/IntArray/IntArray.java: System.loadLibrary("IntArray");
    chap3/IntArray/IntArray.java- }
    chap3/IntArray/IntArray.java-}
    chap3/IntArray2/IntArray.java- static {
    chap3/IntArray2/IntArray.java: System.loadLibrary("IntArray");
    chap3/IntArray2/IntArray.java- }
    chap3/IntArray2/IntArray.java-}
    chap3/ObjectArrayTest/ObjectArrayTest.java- static {
    chap3/ObjectArrayTest/ObjectArrayTest.java: System.loadLibrary("ObjectAr
    ayTest");
    chap3/ObjectArrayTest/ObjectArrayTest.java- }
    chap3/ObjectArrayTest/ObjectArrayTest.java-}
    chap3/Prompt/Prompt.java- static {
    chap3/Prompt/Prompt.java: System.loadLibrary("Prompt");
    chap3/Prompt/Prompt.java- }
    chap3/Prompt/Prompt.java-}
    chap3/Prompt2/Prompt.java- static {
    chap3/Prompt2/Prompt.java: System.loadLibrary("Prompt");
    chap3/Prompt2/Prompt.java- }
    chap3/Prompt2/Prompt.java-}
    chap4/InstanceFieldAccess/InstanceFieldAccess.java- static {
    chap4/InstanceFieldAccess/InstanceFieldAccess.java: System.loadLibrary("
    nstanceFieldAccess");
    chap4/InstanceFieldAccess/InstanceFieldAccess.java- }
    chap4/InstanceFieldAccess/InstanceFieldAccess.java-}
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java- static {
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java: System.loadLibrary(
    InstanceFieldAccess");
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java- }
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java-}
    chap4/InstanceMethodCall/InstanceMethodCall.java- static {
    chap4/InstanceMethodCall/InstanceMethodCall.java: System.loadLibrary("In
    tanceMethodCall");
    chap4/InstanceMethodCall/InstanceMethodCall.java- }
    chap4/InstanceMethodCall/InstanceMethodCall.java-}
    chap4/InstanceMethodCall2/InstanceMethodCall.java- static {
    chap4/InstanceMethodCall2/InstanceMethodCall.java: System.loadLibrary("I
    stanceMethodCall");
    chap4/InstanceMethodCall2/InstanceMethodCall.java- initIDs();
    chap4/InstanceMethodCall2/InstanceMethodCall.java- }
    chap4/InstanceMethodCall2/InstanceMethodCall.java-}
    chap4/MyNewString/MyNewString.java- static {
    chap4/MyNewString/MyNewString.java: System.loadLibrary("MyNewString");
    chap4/MyNewString/MyNewString.java- }
    chap4/MyNewString/MyNewString.java-}
    chap4/MyNewString2/MyNewString.java- static {
    chap4/MyNewString2/MyNewString.java: System.loadLibrary("MyNewString");
    chap4/MyNewString2/MyNewString.java- }
    chap4/MyNewString2/MyNewString.java-}
    chap4/StaticFieldAccess/StaticFieldAccess.java- static {
    chap4/StaticFieldAccess/StaticFieldAccess.java: System.loadLibrary("Stat
    cFieldAccess");
    chap4/StaticFieldAccess/StaticFieldAccess.java- }
    chap4/StaticFieldAccess/StaticFieldAccess.java-}
    chap4/StaticMethodCall/StaticMethodCall.java- static {
    chap4/StaticMethodCall/StaticMethodCall.java: System.loadLibrary("Static
    ethodCall");
    chap4/StaticMethodCall/StaticMethodCall.java- }
    chap4/StaticMethodCall/StaticMethodCall.java-}
    chap5/MyNewString/MyNewString.java- static {
    chap5/MyNewString/MyNewString.java: System.loadLibrary("MyNewString");
    chap5/MyNewString/MyNewString.java- }
    chap5/MyNewString/MyNewString.java-}
    chap6/CatchThrow/CatchThrow.java- static {
    chap6/CatchThrow/CatchThrow.java: System.loadLibrary("CatchThrow");
    chap6/CatchThrow/CatchThrow.java- }
    chap6/CatchThrow/CatchThrow.java-}
    chap6/InstanceMethodCall/InstanceMethodCall.java- static {
    chap6/InstanceMethodCall/InstanceMethodCall.java: System.loadLibrary("In
    tanceMethodCall");
    chap6/InstanceMethodCall/InstanceMethodCall.java- }
    chap6/InstanceMethodCall/InstanceMethodCall.java-}
    chap6/ThrowByName/ThrowByName.java- static {
    chap6/ThrowByName/ThrowByName.java: System.loadLibrary("ThrowByName");
    chap6/ThrowByName/ThrowByName.java- }
    chap6/ThrowByName/ThrowByName.java-}
    chap8/NativeString/NativeString.java- static {
    chap8/NativeString/NativeString.java: System.loadLibrary("NativeString")
    chap8/NativeString/NativeString.java- }
    chap8/NativeString/NativeString.java-}
    chap9/OneToOne/OneToOne.java- static {
    chap9/OneToOne/OneToOne.java: System.loadLibrary("OneToOne");
    chap9/OneToOne/OneToOne.java- }
    chap9/OneToOne/OneToOne.java-}
    chap9/OneToOne/OneToOne.java-
    chap9/SharedStubs/CPointer.java- static {
    chap9/SharedStubs/CPointer.java: System.loadLibrary("disp");
    chap9/SharedStubs/CPointer.java- SIZE = initIDs();
    chap9/SharedStubs/CPointer.java- }
    chap9/SharedStubs/CPointer.java-

    There are 2 choices, i guess:
    1) Catch and don't re-throw, thus allowing pure java methods to be called,
    even though native method calls will throw, and state might be undefined.
    2) Catch and don't re-throw: thus making all method calls on such a class
    to throw, since object instantiations will fail. But at least in this
    case, an object w/ undefined behavior won't be in use.
    And i guess one could choose one or the other based on circumstances. In
    my case, the class will pretty much be unworkable w/o native methods, so
    what would be the best choice?
    Looking at NetBeans source, i'm seeing 2 examples of 1, and 1 example of
    2. Both examples of 1 utilize fail-backs if library isn't found, such as
    not calling the native method involved. The example of 2, catches
    Exception but lets Throwables go thru, which means it doesn't catch
    UnsatisfiedLinkError, and NbDdeBrowserImpl is unusable it library isn't
    found. My situation is similar to this. I concluded for myself, that we
    should catch all 3 exceptions from System.loadLibrary, show error dialog
    w/ each exception's message, and re-throw each exception, because
    otherwise, 90% of methods in the class are going to throw, and there is no
    way to get any decent functionality out of it in such a situation. Would
    you agree w/ my conclusion?
    1.1)
    /tasklist/core/src/org/netbeans/modules/tasklist/core/Background.java
    private static void loadLibrary() {
    if (loadfailed) return;
    if (false == loaded) {
    try {
    // XXX be aware of #32080, that changes location of native
    libraries
    System.loadLibrary("tasklist_bgthreads"); // NOI18N
    loaded = true;
    } catch (Throwable t) {
    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, t);
    loadfailed = true;
    1.2)
    tasklist/timerwin/src/org/netbeans/modules/tasklist/timerwin/AlwaysOnTop.java:
    try {
    setAlwaysOnTopMethod = Window.class.getDeclaredMethod(
    "setAlwaysOnTop", // NOI18N
    new Class[] {Boolean.TYPE});
    } catch (Throwable t) {
    // ignore
    if (setAlwaysOnTopMethod == null) {
    try {
    System.loadLibrary("alwaysontop"); // NOI18N
    libLoaded = true;
    } catch (Throwable t) {
    libLoaded = false;
    2) extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
    try {
    if (org.openide.util.Utilities.isWindows()) {
    // should be 32 or 64 bit, but it may not be present on
    some jdks
    String sunDataModel =
    System.getProperty("sun.arch.data.model"); //NOI8N
    if (sunDataModel != null) {
    if ("64".equals(sunDataModel)) { //NOI18N
    System.loadLibrary(EXTBROWSER_DLL_64BIT);
    } else {
    System.loadLibrary(EXTBROWSER_DLL);
    } else {
    String javaVMName =
    System.getProperty("java.vm.name"); //NOI8N
    if ((javaVMName != null) && (javaVMName.indexOf("64")
    -1)) { //NOI18NSystem.loadLibrary(EXTBROWSER_DLL_64BIT);
    } else {
    System.loadLibrary(EXTBROWSER_DLL);
    } catch (Exception e) {
    DialogDisplayer.getDefault ().notify (
    new
    NotifyDescriptor.Message(NbBundle.getMessage(NbDdeBrowserImpl.class,
    "ERR_cant_locate_dll"),
    NotifyDescriptor.INFORMATION_MESSAGE)
    }

  • Exceptions with JEditorPane setPage() method (Catching not possible)

    hi all
    if anyone can help me...please help
    I got serious exceptions with the JEditorPane()'s setPage() method
    I have written the try & catch still i could not catch the exception..(those exceptions are not displaying any of my program lines)..setPage() mehod was executed properly and the page was displyed on the editorpane..and then exceptions r coming..
    --------my code--------
    java.net.URL fileurl =LongTask.class.getResource(modifiedfilename);
    editorpane.setPage(fileurl);
    ---------------------exceptions
    java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:393)
    at javax.swing.text.SimpleAttributeSet.addAttribute(SimpleAttributeSet.java:176)
    at javax.swing.text.html.CSS.translateHTMLToCSS(CSS.java:687)
    at javax.swing.text.html.StyleSheet.translateHTMLToCSS(StyleSheet.java:491)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.<init>(StyleSheet.java:2476)
    at javax.swing.text.html.StyleSheet.getViewAttributes(StyleSheet.java:312)
    at javax.swing.text.html.BlockView.getAttributes(BlockView.java:275)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.getResolveParent(StyleSheet.java:2609)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.doGetAttribute(StyleSheet.java:2589)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.getAttribute(StyleSheet.java:2569)
    at javax.swing.text.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:105)
    at javax.swing.text.html.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:87)
    at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:60)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.html.BlockView.setParent(BlockView.java:55)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.html.TableView$RowView.replace(TableView.java:1414)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.html.TableView.replace(TableView.java:864)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.html.TableView.setParent(TableView.java:768)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.View.updateChildren(View.java:1126)
    at javax.swing.text.View.insertUpdate(View.java:710)
    at javax.swing.text.View.forwardUpdateToView(View.java:1217)
    at javax.swing.text.View.forwardUpdate(View.java:1192)
    at javax.swing.text.BoxView.forwardUpdate(BoxView.java:222)
    at javax.swing.text.View.insertUpdate(View.java:716)
    at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1487)
    at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1726)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:184)
    at javax.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java:201)
    at javax.swing.text.html.HTMLDocument.insert(HTMLDocument.java:232)
    at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java:3254)
    at javax.swing.text.html.HTMLDocument$HTMLReader.addContent(HTMLDocument.java:3196)
    at javax.swing.text.html.HTMLDocument$HTMLReader.blockClose(HTMLDocument.java:3128)
    at javax.swing.text.html.HTMLDocument$HTMLReader$BlockAction.end(HTMLDocument.java:2334)
    at javax.swing.text.html.HTMLDocument$HTMLReader.handleEndTag(HTMLDocument.java:2233)
    at javax.swing.text.html.parser.DocumentParser.handleEndTag(DocumentParser.java:217)
    at javax.swing.text.html.parser.Parser.parse(Parser.java:2072)
    at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:106)
    at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:78)
    at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:230)
    at javax.swing.JEditorPane.read(JEditorPane.java:504)
    at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:551)
    please share ideas to solve this problem

    But how can I cause GUI thread to run in my thread
    group? As I suppose GUI thread is started by JVM and
    is something separate from my code - I can get a
    reference to GUI thread but don't know how to
    manipulate or replace it...One alternative is to completely separate the GUI code from your code.
    Your code, which is wrapped in appropriate try/catch blocks, runs on its own thread and does its own processing. When it's done with that processing, it queues the results on the event thread for display. If an exception occurs during your processing, then you queue something that notifies the GUI.
    The simplest way to implement this is to spawn a new thread for each operation. The Runnable that you give to that thread looks like the following:
    public MyOperationClass implements Runnable
        public void run()
            try
                // do your exception-generating code here
                SwingUtilities.invokeLater( new MyGUIUpdateClass(param1, param2));
            catch (Exception e)
                SwingUtilities.invokeLater(new MyExceptionReporter(e));
    }This is only a bare-bones solution (and hasn't been compiled). Since it separates the GUI from actual processing, you'll probably want to display a wait cursor while the processing thread is doing its thing. You'll probably end up implementing a class that implements this pattern. You may also want to create a producer-consumer thread, so that the user won't invoke, say, a dozen different operations at once.
    However, this sort of code is absolutely essential to Swing programming. Most apps do extensive non-GUI processing, such as database queries. If you run such queries in the GUI thread, your GUI will freeze.
    Sun has named this pattern "SwingWorker", although I don't think they've fleshed it out very fully: http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

  • How to catch ALL Exception in ONE TIME

    I'm explain my issue:
    I'm making a program with Class, Swing, Thread ...
    Then all action I do on my graphical application, I use a new thread, well
    I want to capture in my Startup programs, all unknow exception and then, I display it with a JOptionPane for example
    In fact, I want to do something like Eclipse, when it crash, I capture the error
    Could you help me ? Tell me the best way to do that ?
    This is an exemple
    FILE: Startup.java
    class Startup{
    public static main (String args[]){
    try{
    new Main();
    }catch(Throwable e){
    //Message d'erreur fenetre
    FILE: Main.java
    class Main{
    Main(){
    init_action();
    void init_action(){
    mybutton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    Thread th=new Thread(){
    public void run(){
    int a = 1 / 0;
    th.start();
    Well, in this example I want to capture the Divide By 0, I use the Throwable Exeption, in order to be sure I catch all unknow exeption
    Then, a good job, is to put throws Throwable in all function
    but Thread, and ActionPerformed ... could not implement it
    How to put this exception and jump it to Startup Program ?

    I already do that, what can I do for improving capture ?
    That's impossible ... It will be a great idea to make a Redirection of Error to a Exception class in futur version
    For example, when an unknow error arrive, don't show it on console and crash ... but run a class redirector exception, and magic, it show you a beautiful error warning, and stop properly the programme ...
    I put an error class, and put try {] catch {} everywhere, and run my exception class,
    this class detect the error exception and run a properly beautiful and clear french message (I'm french :d)
    Well, If you have the BEST other idea, tell me, I read your message with a lot of regard
    see you soon
    bye

  • Best way to catch all exceptions

    What is the best way to proceed if I would like to catch all exceptions in my Swing app?
    If there is an unexpected RuntimeException in my app, I would like to display an error message rather than having the program react silently. Is there a good way of making sure all uncaught exceptions are trapped and reported somewhere in the end? And are there any special inconveniences to such a strategy?

    A very similar question was asked recently. Various solutions were proposed in [this topic|http://forums.sun.com/thread.jspa?forumID=57&threadID=5416873] .

  • To intercept all exception of GUI Swing?

    Blank I tried a method in order to intercept all the exception that can be verified to the inside of a GUI Swing without necessarily to mapping all the code of blocks try & catch.
    I was just trying an interface of the class java.lang.Exception in order to try to make a override of the methods, if there is someone that has already experienced this technique.
    THANKS

    bah, you can throw every exception to the caller method,
    and that one can forward it, too
    I have never tried this, but maybe you can forward all exceptions to
    the main() method, and there should be enough only one try-catch block.
    but then you have declare most of your methods to throw something.
    I advise you to handle errors at least in a very primitive manner,
    only using System.err if you do not want to create some user-friendly,
    GUI-based error treatment.
    println is very good for debugging and development, use it, really.
    First, you can ignore all the exceptions in your code,
    and if something goes wrong, just read your console output
    for more debug info.

  • Can i catch an exception from another thread?

    hi,guys,i have some code like this:
    public static void main(String[] args) {
    TimeoutThread time = new TimeoutThread(100,new TimeOutException("超时"));
    try{
    t.start();
    }catch(Exception e){
    System.out.println("eeeeeeeeeee");
    TimeoutThread will throws an exception when it runs ,but now i can't get "eeeeeeeeeee" from my console when i runs the main bolck code.
    i asked this question in concurrent forums,somebody told me that i can't.so ,i think if i can do this from aspect of jvm.
    thank you for your help
    Edited by: Darryl Burke -- Double post of how to catching exceptions from another thread locking

    user5449747 wrote:
    so ,i think if i can do this from aspect of jvm. What does that mean? You think you'll get a different answer in a different forum?
    You can't catch exceptions from another thread. It's that easy. You could somehow ensure that exceptions from that other thread are always caught and somehow passed to your thread, but that would be a different thing (you would still be catching the exception on the thread it is originating from, as is the only way).
    For example you can use setUncaughtExceptionHandler() on your thread to provide an object that handles an uncaught exceptions (and you could pass that uncaught exception to your other thread in some way).

  • Catch All Exception

    Hi,
    I'm quite familiar with Oracle SOA, OSB , CEP stuff. Just exploring BPM and here i have a question on error handling.
    I see we can catch all system or business exceptions using a event sub process. and handle it. But i see no means to see what the error message is?
    Lets say i would like to email admin with the error message, from where can i retrieve the error message from?
    Any pointers on this is much appreciated.
    Thanks,
    Prakash

    I think you can use Error Events (Component Palette, from the Catch Events section select Error Event) and then log it or email it .
    Ref- 19.5 Handling Exceptions in a Business Process
    http://docs.oracle.com/cd/E21764_01/doc.1111/e15176/errors_bpmpd.htm
    Thanks
    Rupesh

  • A catch-all "exception handler" - what's the end of an stack trace?

    I've created an application that is beeing tested these days, and I thought it would be a good idea to implement a "catch-all" exception handler so that I could notify the user when an exception occur (so that he may stop, send me the log, and to prevent errors that occur as a result of the first one).
    The way I've started implementing it is I redirect error out to a custom output stream:
    public class ConsoleOutStream extends ByteArrayOutputStream {
        private JFrame owner;
        public ConsoleOutStream(JFrame owner) {
            this.owner = owner;
         * Writes <code>len</code> bytes from the specified byte array
         * starting at offset <code>off</code> to this byte array output stream.
         * @param   b     the data.
         * @param   off   the start offset in the data.
         * @param   len   the number of bytes to write.
        public synchronized void write(byte b[], int off, int len) {
            super.write(b, off, len);
            checkForExceptions();
         * Writes the specified byte to this byte array output stream.
         * @param   b   the byte to be written.
        public synchronized void write(int b) {
            super.write(b);
            checkForExceptions();
        private void checkForExceptions() {
            reset();
            if(this.toString().indexOf("xception") != -1) {
                System.out.println("Exception!!\n\n");
                System.out.println(this.toString());
    }then i redirect System.err:
    PrintStream out = new PrintStream(new ConsoleOutStream(this));
    System.setErr(out);
    The problem is that the checkForExceptions() method will be called, e.g. 3 times for each exception - and I just want to display an error message to the user once (of course).
    Anyone done something similar?

    I'm interested in catching all "unhandled errors"how about:
    public static void main(String[] args){
        try{
        //whatever you would normally call from main
        }catch (Throwable e){
             System.out.println("There was an unhandled exception:");
             e.printStackTrace();
    }

Maybe you are looking for

  • Is it possible to Create a viewset in WebDynPro for ABAP-WAS 7.0 ?

    Hi All, Is it possible to Create a viewset in WebDynPro for ABAP-WAS 7.0 ?. or else is there any alternatives for seeing multiple views in single window at once!. Thanks, Sudeep..

  • Problems with latest iTunes version.

    I had installed the latest version of iTunes in my computer, and it works really good, but when i plug my iPod (2nd generation 20GB clickwheel) iTunes shows it and inmediately iTunes stops working. Any help for me? how can i solve this problem? Thanx

  • LOGGING-IN PROBLEM

    I TRIED TO DOWNLOAD FACETIME FOR MAC, HOWEVER, I CANT BECAUSE WHEN I TRIED LOGGING-IN, ERROR MESSAGE: COMPUTER  OR DEVICE CAN'T BE VERIFIED. THANKS FOR THE HELP!

  • Itunes gone crazy! Spurious feeds have suddenly appeared!

    First we had the "unable to submit podcast feed" error. Then there was (and still is) the "cover art not appearing" bug. Now, ladies and gentlemen, I present the "three extra podcast feeds that weren't there before" bug. Try searching for "Parker Sum

  • Convert pdf to word

    I have downloaded trial program.  I want to convert 2 pdf files to word... I can't get into the adobe program to do it