????????????????????????????????????????????con??null????????finally??????????NullPointerException????finally?????????con????null???ж???????????????????
???????????
??????????????
public void method2()
{
try
{
……
method1();  //method1??????????????
}
catch(SQLException e)
{
……
throw new MyException("?????????????:"+e.getMessage);
}
}
public void method3()
{
try
{
method2();
}
catch(MyException e)
{
e.printStackTrace();
……
}
}
????????method2??????У?try?鯰??method1????????????SQLException????????μ????????MyException????δ?????????????????????????????????
????MyException:???????????????????????'MyTable' ??Ч??
????at MyClass.method2(MyClass.java:232)
????at MyClass.method3(MyClass.java:255)
????????SQLException?????????????????????method2???漲???MyException???????????method1?з??????????????????????????????????????method1????????????????????????????????
????JDK???????????????????????????JDK1.4.1?У?Throwable????????????????????public Throwable(Throwable cause)??public Throwable(String message??Throwable cause)??????????д????????????????????printStackTrace?????д????????????????????JDK1.3????????????????????????????????????????????????????????????????????????????????Σ?????????д????????????????printStackTrace????????????????б??????????printStackTrace??????????????super.printStackTrace?????????????????????????????????????????г????MyException??
import java.io.PrintStream;
import java.io.PrintWriter;
public class MyException extends Exception
{
private static final long serialVersionUID = 1L;
//????
private Throwable cause;
//??????
public MyException(Throwable cause)
{
this.cause = cause;
}
public MyException(String s??Throwable cause)
{
super(s);
this.cause = cause;
}
//????printStackTrace?????????????????????
public void printStackTrace()
{
if (cause != null)
{
cause.printStackTrace();
}
super.printStackTrace();
}
public void printStackTrace(PrintStream s)
{
if (cause != null)
{
cause.printStackTrace(s);
}
super.printStackTrace(s);
}
public void printStackTrace(PrintWriter s)
{
if (cause != null)
{
cause.printStackTrace(s);
}
super.printStackTrace(s);
}
}