[SOLVED] Recover from SWT Error [message #664455] |
Sat, 09 April 2011 00:08 |
Jonah Bron Messages: 32 Registered: October 2010 Location: California |
Member |
|
|
Hello, world!
I have almost completed a desktop application that uses SWT. The main() method has a try...catch to catch any exceptions that make it up that far. The exception is passed to a window indicating that a critical error occurred and that the program must close.
The problem is that if any part of SWT produced the exception (e.g. passing null in the second argument of the Image constructor), the error window itself produces an exception, which is not optimal. To be more specific, it's a "SWTException: Invalid thread access" exception, pointing to the line at which the code access the Display.
This indicates to me that SWT is stuck. I tried getting creating a new Display instead of calling Display.getCurrent()/Display.getDefault(), but no joy. How can this be fixed?
[Updated on: Wed, 13 April 2011 22:19] Report message to a moderator
|
|
|
Re: Recover from SWT Error [message #664556 is a reply to message #664455] |
Mon, 11 April 2011 06:14 |
Daniel Krügler Messages: 853 Registered: July 2009 |
Senior Member |
|
|
On 2011-04-09 02:08, Jonah Bron wrote:
> Hello, world!
>
> I have almost completed a desktop application that uses SWT. The main()
> method has a try...catch to catch any exceptions that make it up that
> far. The exception is passed to a window indicating that a critical
> error occurred and that the program must close.
>
> The problem is that if any part of SWT produced the exception (e.g.
> passing null in the second argument of the Image constructor), the error
> window itself produces an exception, which is not optimal. To be more
> specific, it's a "SWTException: Invalid thread access" exception,
> pointing to the line at which the code access the Display.
>
> This indicates to me that SWT is stuck. I tried getting creating a new
> Display instead of calling Display.getCurrent()/Display.getDefault(),
> but no joy. How can this be fixed?
The above exception indicates that you are trying to use SWT components
without being in the SWT thread. Without seeing any code snippet its
hard to give proper advice, especially your phrase "The exception is
passed to a window" hides more than it says. Do you have created this
window before? Or are you trying to open a new dialog? What shell are
you referring to?
My best guess it that you should open your error dialog within an
asyncExec invocation of a display that is associated to original main
window.
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02848 seconds