001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.hayabusa.common; 017 018/** 019 * 共通的に使用されるエクセプションクラスです。 020 * 021 * RuntimeException を継承しているため、try{} catch() {} は不要です。 022 * 本システムでは、すべてこのエクセプションクラスを継承させたクラスを作成し、用途によって、 023 * 使い分けるようにします。つまり、他のどのような、Throwable が発生したとしても、一旦、 024 * try{} catch() {} で受けて、このクラスのサブクラスを、再度 throw させます。 025 * そして、必要であれば、try{} catch() {} を用いて捕まえて、それぞれの対応処理を行います。 026 * 027 * このクラスには、元々の発生したエクセプション( Throwable )を引数にとり、 028 * その printStackTrace()情報を、自分自身のトレース情報に含めます。 029 * また、引数にオブジェクトを渡すことができますので、object.toString() で、オブジェクトの 030 * 状態を表示できるようにしておけば、手軽にデバッグに使うことが可能になります。 031 * 032 * @og.group エラー処理 033 * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバージョン等のシステム関係の情報を付与します。 034 * 035 * @version 4.0 036 * @author Kazuhiko Hasegawa 037 * @since JDK5.0, 038 */ 039public class HybsSystemException extends RuntimeException { 040 private static final long serialVersionUID = 567120130809L ; 041 042 /** システム依存の改行記号をセットします。 */ 043 private static final String CR = System.getProperty("line.separator"); 044 045 /** 4タブの代わりのスペース */ 046 private static final String TAB = " " ; 047 048 /** エラーメッセージに付与するシステム関係の情報 5.6.7.3 (2013/08/23) */ 049 private static final String ERR_INFO = 050 " -------- Exception Information ---------" + CR 051 + TAB + HybsSystem.sys( "OS_INFO" ) + CR // Windows 7 Service Pack 1 052 + TAB + HybsSystem.sys( "SERVER_INFO" ) + CR // 10374232-0004 ( 200.1.50.239 ) 053 + TAB + HybsSystem.sys( "SERVLET_INFO" ) + CR // Apache Tomcat/7.0.42 054 + TAB + TAB + HybsSystem.sys( "TOMCAT_HOME" ) + CR // C:/opengionV6/uap/bin/../../apps/tomcat7.0.42 055 + TAB + HybsSystem.sys( "JDK_INFO" ) + CR // Java HotSpot(TM) Server VM 23.25-b01 056 + TAB + TAB + HybsSystem.sys( "JAVA_HOME" ) + CR // H:/java/tomcat5.5.17 057 + TAB + HybsSystem.sys( "ENGINE_INFO" ) + CR // 5.6.6.0 Release5 Builds (2013182) 058 + TAB + TAB + HybsSystem.sys( "REAL_PATH" ) // C:/opengionV6/uap/webapps/gf/ 059 + TAB + "(" + HybsSystem.sys( "SYSTEM_ID" ) + ")" + CR // GF 060 + " ----------------------------------------" + CR ; 061 062 /** 063 * 詳細メッセージを指定しないで HybsSystemException を構築します。 064 * 065 * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバージョン等の情報を付与します。 066 */ 067 public HybsSystemException() { 068 // 4.3.4.4 (2009/01/01) 069// super(); 070 System.err.println( ERR_INFO ); 071 } 072 073 /** 074 * 指定された詳細メッセージを持つ HybsSystemException を構築します。 075 * 076 * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバージョン等の情報を付与します。 077 * 078 * @param str 詳細メッセージ 079 */ 080 public HybsSystemException( final String str ) { 081 super( str ); 082 System.err.println( ERR_INFO ); 083 } 084 085 /** 086 * 指定された詳細メッセージを持つ HybsSystemException を構築します。 087 * 088 * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバージョン等の情報を付与します。 089 * 090 * @param th 例外Throwableオブジェクト 091 */ 092 public HybsSystemException( final Throwable th ) { 093 super( th ); 094 System.err.println( ERR_INFO ); 095 } 096 097 /** 098 * 指定されたオブジェクトを受け取る HybsSystemException を構築します。 099 * 100 * @og.rev 3.5.5.4 (2004/04/15) 引数を、RuntimeException(String , Throwable )にあわせます。 101 * @og.rev 5.6.7.1 (2013/08/09) エラーに、エンジンのバージョン等の情報を付与します。 102 * 103 * @param str 詳細メッセージ 104 * @param th 例外Throwableオブジェクト 105 * @see java.lang.RuntimeException#RuntimeException(String,Throwable) 106 */ 107 public HybsSystemException( final String str,final Throwable th ) { 108 super( str,th ); 109 System.err.println( ERR_INFO ); 110 } 111 112 /** 113 * この Throwable オブジェクトの詳細メッセージ文字列を返します。 114 * このクラスは、発生元の Throwable の StackTrace を、例外チェーン機能 115 * を利用して取得しています。 116 * また、"org.opengion." を含むスタックトレースのみ、メッセージとして追加します。 117 * 118 * @og.rev 4.0.0.0 (2005/01/31) 例外チェーンを遡ってメッセージを出力します。 119 * 120 * @param thIn Throwableオブジェクト 121 * 122 * @return Throwableの詳細メッセージ 123 */ 124// public static String getLongMessage( final Throwable thIn ) { 125// StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 126// StringBuilder trace = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 127// 128// buf.append( CR ); 129// buf.append( "Version :" ).append( BuildNumber.ENGINE_INFO ).append( CR ); 130// 131// Throwable th = thIn ; 132// while( th != null ) { 133// trace = getStackData( trace,th ); 134// if( th instanceof HybsSystemException ) { 135// buf.append( th.getMessage() ); 136// } 137// else { 138// String msg = th.getMessage(); 139// if( msg != null && buf.indexOf( msg ) < 0 ) { 140// buf.append( msg ); 141// } 142// } 143// buf.append( CR ); 144// th = th.getCause(); 145// } 146// 147// buf.append( trace.toString() ); 148// return buf.toString(); 149// } 150 151 /** 152 * "org.opengion." を含む StackTraceElement のメッセージ文字列を返します。 153 * 154 * @og.rev 4.0.0.0 (2005/01/31) 新規追加 155 * 156 * @param buf StringBuilder 以前のエラーメッセージ 157 * @param th Throwable スタックトレースを取り出すThrowableオブジェクト 158 * 159 * @return "org.opengion." を含む StackTraceElement のメッセージ 160 */ 161// private static StringBuilder getStackData( final StringBuilder buf,final Throwable th ) { 162// if( th != null ) { 163// int cnt = 0; 164// StackTraceElement[] trace = th.getStackTrace(); 165// for( int i=0; i<trace.length; i++ ) { 166// String msg = trace[i].toString(); 167// if( buf.indexOf( msg ) < 0 ) { 168// if( msg != null && msg.indexOf( "org.opengion." ) >= 0 ) { 169// buf.append( "\tat " ).append( msg ).append( CR ); 170// } 171// else if( cnt++ < 5 ) { 172// buf.append( "\tat " ).append( msg ).append( CR ); 173// } 174// else if( cnt++ == 5 ) { 175// buf.append( "\t ......" ).append( CR ); 176// } 177// } 178// } 179// buf.append( "\t ... more ..." ).append( CR ); 180// } 181// return buf; 182// } 183}