Java/JSP/Throw Exceptions

Материал из Java эксперт
Перейти к: навигация, поиск

Throwing an Exception

<html>
    <head>
        <title>Throwing an Exception</title>
    </head>
    <body>
        <title>Throwing an Exception</title>
        <%
        try {
            throw new ArithmeticException("Math Exception!");
        } catch(ArithmeticException e) {
            out.println("Exception message: " + e);
        }
        %>
    </body>
</html>





Throwing Exceptions From Methods

<HTML>
    <HEAD>
        <TITLE>Throwing Exceptions From Methods</TITLE>
    </HEAD>
    <BODY>
        <H1>Throwing Exceptions From Methods</H1>
        <%!
            void doWork() throws ArrayIndexOutOfBoundsException {
                int array[] = new int[10];
                array[100] = 100;
            }
        %>
        <%
            try {
                doWork();
            } catch (ArrayIndexOutOfBoundsException e) {
                out.println("Array out of bounds exception");
            }
        %>
    </BODY>
</HTML>