Rethrowing Exceptions
Line 32 of Fig. H.3 rethrows the exception. Exceptions are rethrown when a catch
block, upon receiving an exception, decides either that it cannot process that exception or that it can only partially process it. Rethrowing an exception defers the exception handling (or perhaps a portion of it) to another catch
block associated with an outer try
statement. An exception is rethrown by using the throw keyword, followed by a reference to the exception object that was just caught. Exceptions cannot be rethrown from a finally
block, as the exception parameter (a local variable) from the catch
block no longer exists.
When a rethrow occurs, the next enclosing try block detects the rethrown exception, and that try
block’s catch
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.