2 Replies Latest reply on Nov 25, 2008 3:14 PM by Peter Johnson

    Exception handling and error in general

    Maziar Aflatoun Newbie


      Hi all,

      I'm pretty new to jsp. I have a class set up that connects to the database and returns the result if successul. I call it from my .jsp which works fine. My question is lets say I force it to cause an exception by chaging the word microsoft in the following statement
      'Class.forName("com.microsoftssss.sqlserver.jdbc.SQLServerDriver"); . How do I show that exception in my jsp since it's been thrown in my class and being caught in the class as well too. What's the best way of doing this?

      Thanks
      Maz

        • 1. Re: Exception handling and error in general
          Peter Johnson Master

          I recommend that the method making the Class.forName() call not catch the exception, or perhaps repackage the caught exception into another exception and throw that. Then let the caller catch the exception. In your case, the code in your JSP would have to catch the exception and generate html to display an error.

          If you do not do this, you would need some other mechanism to propagate the fact that an exception happened, which means that you are just re-inventing exception handling, and it will mean a fair bit of coding that you can avoid by simply using the exception mechanisms.

          • 2. Re: Exception handling and error in general
            Peter Johnson Master

            Oh, one other though. You can have the JSP ignore the exception, and then in your web.xml place an error handler that will display an error page:

            <error-page>
             <exception-type>java.lang.Exception</exception-type>
             <location>/error.html</location>
            </error-page>