???????
??????????????????????????????棬??????????о?????????????????????д???ο????????????????????????????????У?????????????????????????????????????С???????????????????????????????????1????????????????????????????о???????????????????????????????????м??????????????????????????????????????????д??????????????飬????????????????????????????????????????
?????????????
????????????????????????????????δ??????????????????????????????????????????????????????е??????????????????????????????????
???????????????
???????????????????????????????е???????????????????java????????????try?????????????????catch?飬???????????????????catch???е????????????????г???try???з??????????????????С???????????????????catch?飬?????е?finally???????к????????????ThreadGroup??uncaughtException?????????ú????????????????????
?????????
?????????н???Throwable?????Error??Exception???Throwable??RuntimeException??IOException????Exception??Error??RuntimeException??????????δ???????unchecked?????????????????????checked????

????Error??
????Error?????????????????????????????????????????????????????ó????????????У?????JAVA ????????????Error?????unchecked Exception??????????????Error??????????????в??ò???Error????????????????£?????????????????Error?????????
????RuntimeException??
????Exception??????RuntimeException??????????RuntimeException??????RuntimeException ?????Unchecked Exception??????????????????????????RuntimeException??????????????в??????RuntimException????????????????????????????RuntimeException??RuntimeException?????????????????г?????????????????????????????????????????RuntimeException??
????Checked Exception??
????Checked Exception????????????????????Exception?????м????Exception???????RuntimeException????????checked Exception??????е?IOException??ClassNotFoundException??JAVA ????漲?????checked Exception?????????????????????飬??????????????????checked Exception???????catch?????checked Exception???д??????????????????
??????????????????????
????????throws?????
?????????????????????????

??????????????????????????????????????????跽????????????????÷?????????????????????????????????????????????д?????????????????????????????????????к???????????????????
???????????????????????????RuntimeException??Error???????κδ????в???????????????????????????????????????????????????????????????Error??????????????????????????RuntimeException?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????throw??????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????
????????throw??????????????

???????????????????????????????????????????????????????????塣????????????????????ClassCastException????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????????????
??????Java????????????????????????????????????????????????????????????????????????????????????????????????????????
????throw??throws??????
public class TestThrow
{
public static void main(String[] args)
{
try
{
//?????throws?????????????????????????
//??????????main????????????????
throwChecked(-3);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
//???????Runtime????????????????????????
//??????????
throwRuntime(3);
}
public static void throwChecked(int a)throws Exception
{
if (a > 0)
{
//???????Exception??
//??????????try?????????throws???????????
throw new Exception("a???????0???????????");
}
}
public static void throwRuntime(int a)
{
if (a > 0)
{
//???????RuntimeException???????????????????
//??????????????????????????÷????????????
throw new RuntimeException("a???????0???????????");
}
}
}
????????throwChecked?????????????д???????????
public static void throwChecked(int a)
{
if (a > 0)
{
//???????Exception??
//??????????try?????????throws???????????
try
{
throw new Exception("a???????0???????????");
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
????????????main????????throwChecked????try?????
????????????????????????????????в???????
??????????????????????Щ?????δ????????????????Щ???????δ??????
???????finally????????
????finally??????????????????κη????try?飬f(xié)inally?е????????С????????????????????finally?飺
??????1?? try???е???????????????
??????2?? ??try???????????
??????3?? ??try???????return??break??continue??
?????????????????????????????κ?????????????е??????????????Щ???????finally???С???????????????????????????????????????????????????Щ????????д??finally???С?
?????????????????finally???в??????????JAVA??????????????????κ?????±????????finally?????????try?飬?????try???з??????????JAVA??????????finally?????finally???е????finally???????????????????????????finally???????????try?鯰???????????????????????????finally???е??????????try???з???????????????????????????????????
Connection  con = null;
try
{
con = dataSource.getConnection();
……
}
catch(SQLException e)
{
……
throw e;//?????Щ?????????????????????????????
}
finally
{
try
{
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
……
}
}
???????г?????????????????????
????java.lang.NullPointerException
????at myPackage.MyClass.method1(methodl.java:266)