001package votorola.g.lang; // Copyright 2007, 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 003 004/** A catcher that prints exceptions to the standard error stream, 005 * but rethrows errors. 006 */ 007public @ThreadSafe final class CatcherP<S> implements Catcher<S> 008{ 009 010 011 /** A common instance of CatcherP. 012 */ 013 @SuppressWarnings( "unchecked" ) 014 public static <S> CatcherP<S> i() { return (CatcherP<S>)instance; } 015 016 017 018 // - C a t c h e r -------------------------------------------------------------------- 019 020 021 /** Immediately re-throws the error. Subclasses that override this method would 022 * normally also re-throw it (or call super.catchError) taking care not to drop it 023 * first. 024 */ 025 public void catchError( S source, Error r ) { throw r; } 026 027 028 029 /** Calls Catcher.U.printStackTrace( source, x, System.err ). 030 */ 031 public void catchException( S source, Exception x ) 032 { 033 U.printStackTrace( source, x, System.err ); 034 } 035 036 037 038////////////////////////////////////////////////////////////////////////////////////////// 039// Last, so static fields above initialize, and are available during instantiation below 040 041 042 private static final CatcherP<Object> instance = new CatcherP<Object>(); 043 044 045 046}