Monday, October 19, 2009

Overview



















Chapter 12 - Exception Callback

Java Thread Programming
Paul
Hyde






size=1>  size=2>Copyright � 1999 Sams
Publishing




















size=5>Chapter 12: size=5>Exception Callback












size=4>Overview












size=2>Exceptions can be thrown just about anywhere in a Java
program. Methods must declare all of the exceptions they might throw
except for
size=2>RuntimeException
and its subclasses. A
size=2>RuntimeException
can occur on just about every line of code (just think of the fact
that
size=2>NullPointerException size=2> can be thrown anytime a method is invoked if the object
reference s
size=2>nullsize=2>!).












size=2>When an exception occurs and is not immediately caught, it
propagates up the call stack until it either is caught by one of the
invoking methods, or remains uncaught. For methods called from the
size=2>main() method,
the exception can potentially float all the way back up to
size=2>main() and get
reported there. However, when a new thread is spawned, a brand new
call stack is created. This call stack starts with the
color=#010100 face="Courier New" size=2>run() color=#010100 face=Arial size=2> method. The color=#010100 face="Courier New" size=2>run() color=#010100 face=Arial size=2> method does not declare that it
throws any exceptions and should therefore catch all of
them.












size=2>Many times Java developers are frustrated by the fact that
they cannot catch exceptions that occur in other threads. In this
chapter, I’ll show you a way to pass exceptions that occur inside an
active class to another class to signal it that a potential problem
has occurred.












valign="top" bgcolor="#FFFFFF">

Toc



No comments:

Post a Comment