View Javadoc

1   package cz.cuni.amis.utils;
2   
3   /**
4    * Used for adapting APIs throwing exceptions to usecases where this is not desired.
5    * @author ik
6    */
7   public abstract class ExceptionDiscarder<T> {
8   
9       /**
10       * Specifies the task that should be computed. the task can throw exception but
11       * it will be wrapped by run method to a RuntimeException.
12       * @return
13       * @throws java.lang.Exception
14       */
15     protected abstract T task() throws Exception;
16  
17      public T run() {
18          try {
19              return task();
20          } catch (Exception ex) {
21              throw new RuntimeException(ex);
22          }
23      }
24  }