Re: Exceptions in Threads (& MVC)
RedGrittyBrick wrote:
What is a good way to handle exceptions in threads?
The same way you handle exceptions anywhere else. Catch the ones you
know how to handle, and let propagate the ones you don't know how to
handle.
P.S. FooModel catches SQLExceptions but throws FooExceptions since
FooView wants to be storage agnostic.
Thats good practice. Ofcourse, the Runnable.run() method should catch
the FooException and then call EventQueue.invokeLater() to call
fooView.presentExceptionToUser(caughtException);
P.P.S. is buying "Java Concurrency in Practice" overkill for this?
Maybe for this particular problem, but definitely a worth while
purchase. See my review at
<http://virtualinfinity.net/wordpress/technical-book-recommendations/java-concurrency-in-practice/>
P.P.P.S I've Googled, I've skimmed
http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html
and my various Java books.
All good starts. Just because you're dealing with threads, doesn't mean
your design should change. You might have to do a little bit of
footwork to move the exception across threads, but my suggestion about
should help :-)
Oh, and look into the SwingWorker class!
Good luck,
Daniel.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>