View Javadoc
1   /**
2    * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT
3    * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4    */
5   package org.epics.pvmanager;
6   
7   import java.util.concurrent.Executor;
8   import java.util.logging.Level;
9   import java.util.logging.Logger;
10  
11  /**
12   * This class receives all the exceptions generated by a PV.
13   * {@link #handleException(java.lang.Exception) } is called on the thread that
14   * generated the exception. It's up to the handler to handle thread safety
15   * and notification.
16   *
17   * @author carcassi
18   */
19  public class ExceptionHandler {
20  
21      private static final Logger log = Logger.getLogger(ExceptionHandler.class.getName());
22  
23      /**
24       * Notifies of an exception being thrown.
25       * 
26       * @param ex the exception
27       */
28      public void handleException(Exception ex) {
29          log.log(Level.INFO, "Exception for PV", ex);
30      }
31      
32      static ExceptionHandler safeHandler(final ExceptionHandler exceptionHandler) {
33          return new ExceptionHandler() {
34  
35              @Override
36              public void handleException(Exception ex) {
37                  try {
38                      exceptionHandler.handleException(ex);
39                  } catch(RuntimeException e) {
40                      log.log(Level.INFO, "Exception handler throw an exception", e);
41                  }
42              }
43              
44          };
45      }
46  }