SWT: clear before application exits

What's the best way for a SWT application to clean up resources before the application exits? I see two options:

1) Add a DisposeListener to your main window (or better, in Display

). Will it be triggered if an uncaught exception occurs?

2) Use a terminating call . Any issues to be aware of that are not mentioned in the Shutdown Hooks API Design ?

+2


a source to share


1 answer


If an uncaught exception occurs, you can get an java.lang.RuntimeException: Widget disposed too early!

exception:

This is usually caused by one of the other exceptions, especially on close, and often when the errors are "located before early" listed before the exception that caused them. i.e.

  • workbench closes
  • part of the error that cannot be detected.
  • all following parts are not closed and therefore generate this error
  • the error causing the problem seeps up the stack and prints out.


In your case, I'm not sure how this will affect your listener, so the stop hook can be fail-safe, provided it can still access resources to host (which may not always be the case).

+1


a source







All Articles