java - How should I handle exceptions when using SwingWorker? -


I use swingwalkers in Java 6 to avoid running long-running code on the event sender thread.

If my () method gives an exception to the call (), then what is the proper way to resolve the exception?

I'm probably worried about the interrupted exceptions. Javadak's example only ignores the exception, but I've learned in those years that swinging exceptions leads to a hard-to-debug code.

A sample usage is as follows:

  New swingworker & lt; String, null & gt; () {@Override protected String doInBackground ()) throws an exception {// long-running calculation return result; } @ Override protected void () {tryTextField {get ()); } Grip (Interrupted e) e.printStackTrace (); } Hold (execution exception e) {e.printStackTrace (); }}}. Execute (); This is an old post, but I want to make some explanation: 

Swingorker.Get interrupted expiration throws execution exception as a check exception.

Plus it is a very specific uncheck exception that the cancellation exception is undoubtedly it can potentially throw any uncontrolled exception, but the cancellation exception is "extraordinary" and is not unexpected, it is thrown away. After you receive the call, when you try to call to cancel the method.

The executed exception is thrown when an exception is thrown into doInBackground The original exception is wrapped inside an execution exception. When the () method will be called, execution exceptions will be thrown. The idea to remove the original exception and it is good to manage. (As told by Emil H).

The cancellation exception is unruly and should be investigated in my opinion. The sole excuse for API implementation is not that it is not in the form of a check that its status system is (canceled) ().
You can either cancel the test: () and if it is correct then get a call () Canceling it will throw the expansion - Go around with try-hold and add cancellation expansion Because, after being uncontrolled, the compiler will not be requested - The fact is that the cancellation exception has not been investigated, free to do all you forget and get it all a good surprise

please do anything You will not cancel the worker

Interruption exception If you cancel a swingthread with the cancellation (true) then call the first interruptible method call (Thread to make sure sleep, this.wait, Maybe some IO methods) will throw InterruptException into doInBackground. But this exception is not wrapped in ExecuteException. DoInBackground is left to end with the interrupted exception. If it has been caught and replaced with any other exception, then it will be ignored, because switcheddown has been implemented on EDT before it can be canceled by this moment, and if found, then Only standard cancellation exceptions have been found. Embarrassed not an exception!

If you cancel with cancellation (false), an interrupt exception is raised inside the doInBackground, if you cancel with the same (real), but no interrupt Do not Call Into InBackground In these cases, doInBackground will follow its natural loop. This loop should test the isCancelled method and should gracefully get out. If doInBackground does not do this, then it will run forever. I have not tested the presence of timeouts, but I do not accept it.

For me, it's just a gray area . In which cases have been interrupted? I want to see some short codes, because I could not produce the same exception: -)

P.S. I have documented another question and answer that in case of cancellation, and the state change listener is said before the INA-Background front. Since this is true, this is not a bug - a special attention is required when you are intrested in designing the doInBackground method, see


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -