Using the throws Clause

Now let’s examine method quotient (Fig. H.2, lines 9–13). The portion of the method declaration located at line 10 is known as a throws clause. It specifies the exceptions the method throws. This clause appears after the method’s parameter list and before the method’s body. It contains a comma-separated list of the exceptions that the method will throw if various problems occur. Such exceptions may be thrown by statements in the method’s body or by methods called from the body. A method can throw exceptions of the classes listed in its throws clause or of their subclasses. We’ve added the throws clause to this application to indicate to the rest of the program that this method may throw an ArithmeticException. Clients ...

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.