首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

EXCEPTION有关问题

2012-03-15 
EXCEPTION问题packagecom.jivesoftware.forumimportjava.io.PrintStreamimportjava.io.PrintWriter/***

EXCEPTION问题
package   com.jivesoftware.forum;  

import   java.io.PrintStream;  
import   java.io.PrintWriter;  

/**  
*   Thrown   if   a   User   does   not   have   permission   to   access   a   particular   method.  
*  
*   @author   yangyong  
*  
*/  
public   class   UnauthorizedException   extends   Exception   {  

private   Throwable   nestedThrowable   =   null;  

public   UnauthorizedException()   {  
super();  
//   TODO   Auto-generated   constructor   stub  
}  

public   UnauthorizedException(String   message)   {  
super(message);  
//   TODO   Auto-generated   constructor   stub  
}  

public   UnauthorizedException(Throwable   nestedThrowable)   {  
this.nestedThrowable=nestedThrowable;  
}  

public   UnauthorizedException(String   msg,   Throwable   nestedThrowable)   {  
super(msg);  
this.nestedThrowable=nestedThrowable;  
}  

public   void   printStackTrace(){  
super.printStackTrace();  
if(nestedThrowable!=null){  
nestedThrowable.printStackTrace();  
}  
}  

public   void   printStackTrace(PrintStream   ps){  
super.printStackTrace(ps);  
if(nestedThrowable!=null){  
nestedThrowable.printStackTrace(ps);  
}  
}  

public   void   printStackTrace(PrintWriter   pw){  
super.printStackTrace(pw);  
if(nestedThrowable!=null){  
nestedThrowable.printStackTrace(pw);  
}  
}  
}  
今天看了一下这个自定义的类,为什么要先用super.printStackTrace(pw);后用  
if(nestedThrowable!=null){  
nestedThrowable.printStackTrace(pw);  
}?   不是只用一条nestedThrowable.printStackTrace(pw);不就行了吗,   这是为什么呢  


[解决办法]
super.printStackTrace(pw);
========================================
让你显示的调用一下基类的这个有参函数。因为你的方法要重写super的这个方法,而这个方法是基于原来的基础上增加功能,这样,用一下super.printStackTrace(pw);直接在将你的新增加的功能放进去就行了。

热点排行