Uploaded image for project: 'Commons Chain'
  1. Commons Chain
  2. CHAIN-67

Refactor of explicit Exception throws to a RuntimeException type

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.0
    • None

    Description

      As I've been working on the examples and the documentation for v2 of
      chain, I've noticed that the API for exception handling of Command and
      Chain is clunky.

      When executing a command like:

             ProfileContext context = new ProfileContext();
             Command<String, Object, ProfileContext> command = new ProfileCheck();
      
             try {
                 command.execute(context);
             }
             catch (Exception e) {
                 throw new RuntimeException(e);
             }
      

      The user of chain has to explicitly catch Exception. If the desire was
      to catch the most base error and force the user to deal with it, why
      aren't we using Throwable? Anyways, this design leads to less than
      elegant code and since we will be breaking the API in v2, I would like
      to suggest a different approach.

      I suggest that Command and Chain should throw a custom exception class
      called ChainException that inherits from RuntimeException. And in the
      CommandBase, ChainBase we wrap the catch of Exception in this runtime
      exception. Moreover, we would attach to ChainException some optional
      debug information about the Context invoked when the exception was
      encountered.

      Attachments

        1. chain-67.diff
          31 kB
          Elijah Zupancic

        Activity

          People

            simone.tripodi Simone Tripodi
            elijah Elijah Zupancic
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified