Uploaded image for project: 'Log Tool'
  1. Log Tool
  2. LOGTOOL-124

Ability to provide exception producer

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Minor Minor
    • 2.1.0.Beta1
    • None
    • None

      Sometimes you must use the same exception message for many different types of exception. It would be nice if you could give a parameter which can produce an exception, like this:

      public interface MyLogs {
          // ...
          @Message(id = 1234, "The operation failed due to %s")
          <T extends Throwable> T operationFailed(@Producer Function<String, T> fn, String thing);
      }
      

      And later at usage:

          // ...
          throw MyLogs.log.operationFailed(IOException::new, "thingy");
      

      A valid function parameter must return a type which is equal or assignable to the return type, and is assignable to Throwable. Other than that, it can be treated the same as as if you were dealing with a constructor class that has exactly one constructor, using the same matching/inference logic, meaning you could also accept BiFunction which accepts two arguments.

            jperkins-rhn James Perkins
            dlloyd@redhat.com David Lloyd
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: