Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » [SOLVED] Recover from SWT Error
[SOLVED] Recover from SWT Error [message #664455] Sat, 09 April 2011 00:08 Go to next message
Jonah Bron is currently offline Jonah BronFriend
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 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
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
Re: Recover from SWT Error [message #664734 is a reply to message #664455] Mon, 11 April 2011 18:33 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Hey Daniel, thanks for the reply. I tried that, but the program sat there as if stuck. The error window never appears, but the program does not terminate. It appears that it's waiting for the Display object.
Re: Recover from SWT Error [message #664827 is a reply to message #664734] Tue, 12 April 2011 08:28 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2011-04-11 20:33, Jonah Bron wrote:
> Hey Daniel, thanks for the reply. I tried that, but the program sat
> there as if stuck. The error window never appears, but the program does
> not terminate. It appears that it's waiting for the Display object.

You need to provide a minimal snippet, otherwise it's impossible to
argue about program behavior.

- Daniel
Re: Recover from SWT Error [message #664916 is a reply to message #664827] Tue, 12 April 2011 13:34 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Something to try quickly is to use display.syncExec() rather than
display.asyncExec(). If this does not help then yes, a snippet or some
means of reproducing the problem is needed (ideal snippet template:
http://www.eclipse.org/swt/faq.php#whatisasnippet ).

Grant


"Daniel Kr
Re: Recover from SWT Error [message #665025 is a reply to message #664455] Tue, 12 April 2011 22:13 Go to previous message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Alright, apparently the problem was elsewhere. Part of the problem was that I set it to new Display() instead of Display.getDefault() Rolling Eyes . A bit confusing, but it's sorted out now. FYI, I didn't end up needing syncExec or asyncExec.

Thanks everyone.
Previous Topic:Delete / Resize rectangles in a Canvas
Next Topic:SWT large component widget question
Goto Forum:
  


Current Time: Fri Apr 19 02:03:00 GMT 2024

Powered by FUDForum. Page generated in 0.02081 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top