001package votorola.g.lang; // Copyright 2006, 2009, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. 002 003import java.util.logging.Level; 004import votorola.g.logging.LoggerX; 005 006 007/** A catcher that logs exceptions, but rethrows errors. 008 */ 009public @ThreadSafe class CatcherL<S> implements Catcher<S> 010{ 011 012 013 /** Constructs a CatcherL. 014 * 015 * @see #loggingLevel() 016 */ 017 public CatcherL( Level _loggingLevel ) { loggingLevel = _loggingLevel; } 018 019 020 021 // ------------------------------------------------------------------------------------ 022 023 024 /** The level at which caught exceptions are logged. 025 */ 026 public final Level loggingLevel() { return loggingLevel; } 027 028 029 private final Level loggingLevel; 030 031 032 033 // - C a t c h e r -------------------------------------------------------------------- 034 035 036 /** Immediately re-throws the error. Subclasses that override this method would 037 * normally also re-throw, by calling super.catchError. 038 */ 039 public void catchError( S source, Error r ) { throw r; } 040 041 042 043 /** Logs a full stack trace of the exception, using the source's associated logger. 044 */ 045 public void catchException( S source, Exception x ) { log( source, x ); } 046 047 048 049//// P r i v a t e /////////////////////////////////////////////////////////////////////// 050 051 052 /** Logs a full stack trace of the throwable, using the source's associated logger. 053 */ 054 protected final void log( final S source, final Throwable t ) 055 { 056 LoggerX.i(source.getClass()).log( loggingLevel, /*message*/"", t ); 057 } 058 059 060 061}