Announcement Announcement Module
Collapse
No announcement yet.
Proper Web Exception Handling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Proper Web Exception Handling

    What would be the best approach to handling DataAccessExceptions that are thrown when invoking methods on a DAO within a Form Controller?

    From reading the Spring IN Action, Pro Spring, and online Spring reference documentation, I believe you have many ways to skin that cat.

    1. HandlerExceptionResolver - This will allow you to map exception class to view names. How do I use this class? Where do i wire it?

    2. web.xml - The web module configuration will allow me to map exception classes to specific JSPS.

    3. Programatically - The form controller could try/catch the exception and then return an error ModelAndView.

    Any suggestions? Any recommendations? Any sample code/configuration?

    Thanks in Advance!

  • #2
    Re: Proper Web Exception Handling

    Originally posted by mzupper
    What would be the best approach to handling DataAccessExceptions that are thrown when invoking methods on a DAO within a Form Controller?

    From reading the Spring IN Action, Pro Spring, and online Spring reference documentation, I believe you have many ways to skin that cat.

    1. HandlerExceptionResolver - This will allow you to map exception class to view names. How do I use this class? Where do i wire it?

    2. web.xml - The web module configuration will allow me to map exception classes to specific JSPS.

    3. Programatically - The form controller could try/catch the exception and then return an error ModelAndView.

    Any suggestions? Any recommendations? Any sample code/configuration?

    Thanks in Advance!
    Personally, I use method no. 2.

    No. 1 would be OK, though never used it.

    Steer clear of no. 3. You don't really want to do this kind of exception handling programmatically, especially if/when your application gets larger. You'll be doing a lot of find/replace if you want to change some behaviour.

    Bob

    Comment


    • #3
      I am currently using approach #2, but how do I pass query string parameters/reference data to the error JSP?

      Comment


      • #4
        Originally posted by mzupper
        I am currently using approach #2, but how do I pass query string parameters/reference data to the error JSP?
        I thought you were talking about catastrophic errors like DataAccessExceptions, so you should only be showing a standard error page really and logging the exception somewhere else.

        If you want to display the exception on the page then you can display the exception on the page with <%= exception %>

        Bob

        Comment


        • #5
          sorry bob, you are right... catastrophic errors would be logged to a generic JSP that does not require any parameters/reference data.

          Comment

          Working...
          X