3 Replies Latest reply: Dec 10, 2012 11:51 PM by Kayaman RSS

    Not able to handle the exception in web application

      In my web application i m trying to handle the run time exception with the help of <exception-type> and <location> tag in web.xml file as show below.

      But whille running the application the exeception raised when n>5 is not handled and i am getting internal server error with root cause as " coreservlets.DumbDeveloperException: Value of n is greater than 5 ".

      I have kept all the files in the proper path and directory and i am using Tomcat 7.0.27.

      Kindly help me how to sort it out.

      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
      the other files of my web applications are given below.

      package coreservlets;
      public class DumbDeveloperException extends Exception {
        public DumbDeveloperException() {
          super("Value of n is greater than 5");
        public static int dangerousComputation(int n)
            throws DumbDeveloperException {
          if (n < 5) {
            return(n + 10);
          } else {
            throw(new DumbDeveloperException());
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <HEAD><TITLE>Risky JSP Page</TITLE></HEAD>
          <BODY BGCOLOR="#FDF5E6">
             <h2>Risky Calculations </h2>
              <%@ page import="coreservlets.*" %>
              <% int n = ((int) (10 * Math.random()));%>
                  <LI>n: <%= n%>
                  <LI>dangerousComputation(n): <%= DumbDeveloperException.dangerousComputation(n)%>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <BODY BGCOLOR="#FDF5E6">
              <H2>Dumb Developer</H2>
              We're brain dead. Consider using our competitors.