Re: Handling exceptions in SwingWorker




Rogan Dawes wrote:
Michael Rauscher wrote:
Efi Merdler wrote:
Hello,
I didn't find any information on this subject.
Let's assume that I have an exception while running my background
method, what are my available options :
1. Handle the exception from within the background method, sometimes
not possible especially if it requires handling GUI.
2. Create a getter method called getException() that returns the
exception if one exists and null if none exists.

OK, I'd like to add some possibilities:

3. Use a global 'ErrorManager'

4. Create an 'ExceptionListener' and a method addExceptionListener

5. Use a combination of 3 and 4

Bye
Michael

6. Extend SwingWorker to have both a done() and exception(Exception e)
method, both of which are called on the EDT. Depending on requirements,
you may want both methods to be called if an Exception occurs, or the
exception() method could chain to the done() method.

7. Catch the exception in your worker method, and set the return value
to the exception. In your done() method, check if you get an instance of
Exception and handle it appropriately.

Rogan

Great !
How do you call a method on the EDT, do you use
SwingUtilities.InvokeLater(new Runner(...
exception(e));

?

Thanks,
Efi

.



Relevant Pages

  • Re: catching an unhandled exception
    ... > creates an exception and then counts the ammount of elements and write ... so that the top-level exception handler does not receive the exception. ... Rogan Dawes ... Please respond to "nntp AT dawes DOT za DOT net" ...
    (comp.lang.java.programmer)
  • Re: Handling exceptions in SwingWorker
    ... Michael Rauscher wrote: ... Handle the exception from within the background method, ... Extend SwingWorker to have both a doneand exceptionmethod, both of which are called on the EDT. Depending on requirements, you may want both methods to be called if an Exception occurs, or the exceptionmethod could chain to the donemethod. ...
    (comp.lang.java.gui)
  • Re: Exceptions throughout multiple classes
    ... How do I 'break' this chain when an error occurs in D? ... to tell A that something went wrong, is either rethrow every exception ... Razzie ... >> I was really wondering if catching and rethrowing an exception is very ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TargetInvocationException makes no sense
    ... One can browse the chain by adding the exception variable to the Watch ... The key property is InnerException - you should ...
    (microsoft.public.dotnet.general)
  • Re: TargetInvocationException makes no sense
    ... One can browse the chain by adding the exception variable to the Watch ... The key property is InnerException - you should ...
    (microsoft.public.dotnet.general)