Velocity
  1. Velocity
  2. VELOCITY-409

Convert Exceptions to RuntimeExceptions

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.5
    • Component/s: Engine
    • Labels:
      None

      Description

      There's a movement in the field to simplify Java development by using unchecked Exceptions rather than checked Exceptions. Most notably this approach has been championed by Rod Johnson (J2EE without EJB, Spring Framework) and Bruce Eckels (Thinking in Java). In the last 2 years, popular libraries like Spring Framework and Hibernate 3.0 have used unchecked exceptions.

      Quote from the DeveloperWorks article listed below:

      "Some exceptions are basically secondary return codes (which generally signal violation of business rules), and some are of the "something went horribly wrong" variety (such as failure to make a database connection). Johnson advocates using checked exceptions for the first category (alternative return codes), and runtime exceptions for the latter category. In the "something went horribly wrong" category, the motivation is simply to recognize the fact that no caller is going to effectively handle this exception, so it might as well get propagated all the way up the stack with the minimum of impact on the intervening code (and minimize the chance of exception swallowing)."

      I'd argue that Velocity exceptions like ParseException and ResourceNotFoundException are of the "horribly wrong" category. Probably MethodInvocationException as well. In version 2.0, we should consider making VelocityException a subclass of java.lang.RuntimeException.

      Resources:

      http://www-128.ibm.com/developerworks/java/library/j-jtp05254.html

      Here's an argument against this practice:
      http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html

        Activity

        Hide
        Henning Schmiedehausen added a comment -

        I do second that notion. Runtime exceptions are the way to go.

        Show
        Henning Schmiedehausen added a comment - I do second that notion. Runtime exceptions are the way to go.
        Hide
        Henning Schmiedehausen added a comment -

        We boldly moved VelocityException to extend RuntimeException between beta1 and beta2. Beware of flying pigs overhead.

        Show
        Henning Schmiedehausen added a comment - We boldly moved VelocityException to extend RuntimeException between beta1 and beta2. Beware of flying pigs overhead.
        Hide
        Henning Schmiedehausen added a comment -

        Close all resolved issues for Engine 1.5 release.

        Show
        Henning Schmiedehausen added a comment - Close all resolved issues for Engine 1.5 release.

          People

          • Assignee:
            Unassigned
            Reporter:
            Will Glass-Husain
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development