代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
异常处理类
作者:
/ 发布于
2011/1/14
/
724
<div><span style="color: #008000">/**</span><span style="color: #008000"> * (#)ThrowableManager.java 1.0 Apr 10, 2008 * * Copyright 2007- wargrey , Inc. All rights are reserved. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">package</span><span style="color: #000000"> net.wargrey.application; </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.awt.Component; </span><span style="color: #0000ff">import</span><span style="color: #000000"> javax.swing.JOptionPane; </span><span style="color: #008000">/**</span><span style="color: #008000"> * This class ExceptionManager and its subclasses are a form of * Exception. It is used to wrap all the Throwable instances * and handle them in a unified way. It will show the information which consists of * StackTraces and Messages by using JOptionPanel. * * </span><span style="color: #808080">@author</span><span style="color: #008000"> Estelle * </span><span style="color: #808080">@version</span><span style="color: #008000"> 1.0 * </span><span style="color: #808080">@see</span><span style="color: #008000"> java.lang.Exception * </span><span style="color: #808080">@since</span><span style="color: #008000"> jdk 1.5 </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> ExceptionManager </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Exception { </span><span style="color: #008000">/**</span><span style="color: #008000"> * This field alerter is used to show the information the Class offered. * * </span><span style="color: #808080">@see</span><span style="color: #008000"> javax.swing.JOptionPane </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">private</span><span style="color: #000000"> JOptionPane alerter; </span><span style="color: #008000">/**</span><span style="color: #008000"> * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(String msg). * * </span><span style="color: #808080">@param</span><span style="color: #008000"> msg The message will pass the specified constructor * </span><span style="color: #808080">@return</span><span style="color: #008000"> An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(String msg). </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> ExceptionManager wrap(String msg){ </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ExceptionManager(msg); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(Throwable throwable). * * </span><span style="color: #808080">@param</span><span style="color: #008000"> throwable The cause will pass the specified constructor * </span><span style="color: #808080">@return</span><span style="color: #008000"> An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(Throwable throwable). </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> ExceptionManager wrap(Throwable throwable){ </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ExceptionManager(throwable); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(String msg,Throwable throwable). * * </span><span style="color: #808080">@param</span><span style="color: #008000"> msg The message will pass the specified constructor * </span><span style="color: #808080">@param</span><span style="color: #008000"> throwable The cause will pass the specified constructor * </span><span style="color: #808080">@return</span><span style="color: #008000"> An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(String msg, Throwable throwable) </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> ExceptionManager wrap(String msg,Throwable throwable){ </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ExceptionManager(msg,throwable); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Constructs a new instance with the specified detail message. The concrete handler * is its super class. This constructor always used to construct a custom exception * not wrapping the exist exception. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> msg the detail message which is the part of the information will be * shown. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> ExceptionManager(String msg){ </span><span style="color: #0000ff">super</span><span style="color: #000000">(msg); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Constructs a new instance with the specified detail cause. The concrete handler * is its super class. This constructor always used to wrap an exist exception. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> throwable the cause which has been caught. It's detail message and * stacktrace are the parts the information will be shown. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> ExceptionManager(Throwable throwable){ </span><span style="color: #0000ff">super</span><span style="color: #000000">(throwable); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Constructs a new instance with the specified detail message and cause. The * concrete handler is its super class. This constructor always used to construct * an exception wrapping the exist exception but requires a custom message. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> msg the detail message which is the part of the information will * be shown. * </span><span style="color: #808080">@param</span><span style="color: #008000"> throwable the cause which has been caught. It's stacktrace is the parts * the information will be shown. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> ExceptionManager(String msg,Throwable throwable){ </span><span style="color: #0000ff">super</span><span style="color: #000000">(msg,throwable); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Show the information with everything is default. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">synchronized</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> alert(){ alert((Component)</span><span style="color: #0000ff">null</span><span style="color: #000000">); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Show the information in a dialog with the specified title * "ThrowableManager Alerter". The dialog belongs to the given component which * default is the screen. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> parent The component cause the exception. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">synchronized</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> alert(Component parent){ alert(parent,</span><span style="color: #000000">"</span><span style="color: #000000">ThrowableManager Alerter</span><span style="color: #000000">"</span><span style="color: #000000">); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Show the information in a dialog with the specified title. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> title The title of the dialog. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">synchronized</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> alert(String title){ alert((Component)</span><span style="color: #0000ff">null</span><span style="color: #000000">,title); } </span><span style="color: #008000">/**</span><span style="color: #008000"> * Show the information in a dialog which has the specified title and belongs to the * specified component. * * </span><span style="color: #808080">@param</span><span style="color: #008000"> parent The component cause the exception. * </span><span style="color: #808080">@param</span><span style="color: #008000"> title The title of the dialog. </span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">synchronized</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> alert(Component parent,String title){ StringBuilder errorMessage</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> StringBuilder(); errorMessage.append(</span><span style="color: #0000ff">this</span><span style="color: #000000">.toString()); </span><span style="color: #0000ff">for</span><span style="color: #000000"> (StackTraceElement st:((</span><span style="color: #0000ff">this</span><span style="color: #000000">.getCause()</span><span style="color: #000000">==</span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span style="color: #000000">?</span><span style="color: #0000ff">this</span><span style="color: #000000">:</span><span style="color: #0000ff">this</span><span style="color: #000000">.getCause()).getStackTrace()){ errorMessage.append(</span><span style="color: #000000">"</span><span style="color: #000000">\n\t at </span><span style="color: #000000">"</span><span style="color: #000000">); errorMessage.append(st.toString()); } alerter.showMessageDialog(parent, errorMessage, title ,JOptionPane.ERROR_MESSAGE); } }</span> </div>
试试其它关键字
异常处理
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3