Java???????
???????????? ???????[ 2012/9/13 11:05:11 ] ????????
??Java??????????????????????????????Java??????????????????????????????????????????????????????????????????飬?????????????????????????????????????????????????????
????????г???????????У?????????????????????裺
????1???????????????????????????????????? extends Exception??
????2?????????????????throw?????????
????3?????????????????????д?????????????try-catch?????????????????????????????????????throws??????????????????????
????4???????????????????в???????????
???????????????????????????????????????????????????
???????????????????????????£?
/** *<p>Titlt:?????????NumeratorIsZeroException</p> *<p>Description:??????????</p> *<p>Copyright:copyright(c) 2012</p> *<p>Filename:NumeratorIsZeroException.java</p> *@authorWang Luqing *@version1.0 */ class NumeratorIsZeroException extends Exception { public NumeratorIsZeroException(String msg) { super(msg); } } |
???????????????????????????????£?
/** *<p>Titlt:?????Number/p> *<p>Description:?????г?????????</p> *<p>Copyright:copyright(c) 2012</p> *<p>Filename:Number.java</p> *@authorWang Luqing *@version1.0 */ public class Number { public int divition(int iNum1??int iNum2)throws NumeratorIsZeroException { if(0 == iNum2) { throw new NumeratorIsZeroException("??????????"); } return (iNum1/iNum2); } } |
/** *<p>Titlt:?????Test</p> *<p>Description:??????????????</p> *<p>Copyright:copyright(c) 2012</p> *<p>Filename:Test.java</p> *@authorWang Luqing *@version1.0 */ public class Test { public static void main(String[] args) { Number num = new Number(); try { System.out.println("???" + num.divition(12??0)); } catch(NumeratorIsZeroException e) { System.out.println(e.getMessage()); e.printStackTrace(); } catch(Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } } |
???????н???????????
??????????????
????NumeratorIsZeroException????????????
????at Number.divition(Number.java:15)
????at Test.main(Test.java:17)
???????
????1???????????????????????????????????????????????????????????
????2??getMessage()??????????????printStackTrace()?????????????????????
????3?????????ú??????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11