JSP: Création d’une classe de gestion d’exception personnalisée

 
<HTML>
    <HEAD>
        <TITLE>Creating a Custom Exception Object</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Creating a Custom Exception Object</H1>
        <%!
            class NewException extends Exception 
            {
                int value;
 
                public String toString() 
                {
                    return "NewException " + value;
                }
 
                NewException(int v) 
                {
                    value = v;
                }
            }
 
            void doWork(int value) throws NewException 
            {
                if(value == 0){
                    throw new NewException(value);
            }
        }
    %>
 
    <%
        try {
            doWork(3);
            doWork(0);
        } catch (NewException e) {
            out.println("Exception: " + e);
        }
    %>
    </BODY>
</HTML>
           
       

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>