Using a try/catch Block : Try Catch « JSP « Java






Using a try/catch Block

<HTML>
    <HEAD>
        <TITLE>Using a try/catch Block</TITLE>
    </HEAD>

    <BODY>
        <H1>Using a try/catch Block</H1>
    <%
        try{
            int i = 1;
            i = i / 0;
            out.println("The answer is " + i);
        }
        catch (Exception e){
            out.println("An exception occurred: " + e.getMessage());
        }
    %>
    </BODY>
</HTML>


           
       








Related examples in the same category

1.Nesting try/catch Statements
2.Printing a Stack Trace to the Server Console
3.Multiple Catch