freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

java異常處理ppt課件-資料下載頁

2025-01-14 07:05本頁面
  

【正文】 4 拋出 異常 class ExceptionTry { public void run ( byte k ) throws Exception { byte y = 1, i 。 for (i = 1。 i = k。 i ++ ) { if ( y / i ) throw new Exception(overflow)。 else y = (byte) ( y * i )。 } ( k + ! = + y )。 } public static void main (String args[]){ … for (byte i=1。i8。i++) { try { (i)。} catch (Exception e ) { (())。 (0)。 } } } } i=5時(shí) 5! = 120 2022年 2月 11日星期五 NCEPU 4 拋出 異常 class ExceptionTry { public void run ( byte k ) throws Exception { byte y = 1, i 。 for (i = 1。 i = k。 i ++ ) { if ( y / i ) throw new Exception(overflow)。 else y = (byte) ( y * i )。 } ( k + ! = + y )。 } public static void main (String args[]){ … for (byte i=1。i8。i++) { try { (i)。} catch (Exception e ) { (())。 (0)。 } } } } i=6時(shí) 5! = 120 overflow 2022年 2月 11日星期五 NCEPU 例 程序運(yùn)行時(shí),在 calc方法中生成的異常,通過調(diào)用棧 傳遞給 run方法,由 run方法進(jìn)行處理 pu bli c c las s T r y 6{ pu bli c v oid ca lc( by t e k ) t hr ow s E xc ep t ion / / 拋出異常 { by t e y = 1,i= 1。 S y s t em .out .pr int ( k+ != ) 。 f or ( i= 1。i 〈 = k。i + + ) { if ( y B y t A X _V A LU E / i) t hr ow new E xce pt ion( ov er f low ) 。 els e y = ( by t e) ( y * i) 。 } S y s t em .out .pr int ln( y ) 。 } pu bli c v oid r un ( by t e k ) / / 捕獲并處理異常 {2022年 2月 11日星期五 實(shí)例 class ExceptionRaised { public ExceptionRaised() { } public int calculate( int operand1, int operand2) { int result = operand1 / operand2。 return result。 } public static void main(String[] args) { ExceptionRaised obj = new ExceptionRaised()。 int result = (9, 0)。 (result)。 } } 2022年 2月 11日星期五 解決方案一 class ExceptionRaised { public ExceptionRaised() { } public int calculate( int operand1, int operand2) { int result=0。 try { result = operand1 / operand2。 } catch (Exception e) { (發(fā)生異常: + ())。 ()。 } return result。 } public static void main(String[] args) { ExceptionRaised obj = new ExceptionRaised()。 int result = (9, 0)。 (result)。 } } 2022年 2月 11日星期五 class ExceptionRaised { public ExceptionRaised() { } public int calculate( int operand1, int operand2) throws Exception{ int result=0。 result = operand1 / operand2。 return result。 } } class ArithmeticException { public static void main(String[] args) { ExceptionRaised obj = new ExceptionRaised()。 try { int result = (9, 0)。 (result)。 } catch(Exception e) { (0不能做除數(shù)! )。 } } } 解決方案二 2022年 2月 11日星期五 解決方案三 class ExceptionRaised { public ExceptionRaised() { } public int calculate( int operand1, int operand2) throws Exception{ int result=0。 result = operand1 / operand2。 return result。 } } class ArithmeticException { public static void main(String[] args) throws Exception { ExceptionRaised obj = new ExceptionRaised()。 int result = (9, 0)。 (result)。 } } 用 throws聲明拋出異常 2022年 2月 11日星期五 Java提供的內(nèi)置異常不能滿 足程序需要怎么辦? 那就自定義 異常吧??! 5 創(chuàng)建 異常類 使用自定義的異常 步驟: 。 ,并用 throw語句拋出。 throws語句聲明該方法可能拋出的異常。 2022年 2月 11日星期五 NCEPU 5 創(chuàng)建 異常類 class MyException extends Exception { private int detail。 MyException ( int a ) { detail = a。 } public String toString() { return MyException[+detail+])。 } } class ExceptionDemo { static void puter (int a) throws MyException{ (Called puter:+a)。 if (a10) throw new MyException(a)。 (Normal exit)。 } public static void main (String args[]){ try { puter (1)。 puter (20) 。 } catch (MyException e ) { (e)。 }}} 2022年 2月 11日星期五 NCEPU 5 創(chuàng)建 異常類 class MyException extends Exception { private int detail。 MyException ( int a ) { detail = a。 } public String toString() { return MyException[+detail+])。 } } class ExceptionDemo { static void puter (int a) throws MyException{ (Called puter:+a)。 if (a10) throw new MyException(a)。 (Normal exit)。 } public static void main (String args[]){ try { puter (1)。 puter (20) 。 } catch (MyException e ) { (e)。 }}} Called puter: 1 Normal exit 2022年 2月 11日星期五 NCEPU 5 創(chuàng)建 異常類 class MyException extends Exception { private int detail。 MyException ( int a ) { detail = a。 } public String toString() { return (MyException[+detail+])。 } } class ExceptionDemo { static void puter (int a) throws MyException{ (Called puter:+a)。 if (a10) throw new MyException(a)。 (Normal exit)。 } public static void main (String args[]){ try { puter (1)。 puter (20) 。 } catch (MyException e ) { (e)。 }}}//調(diào)用 toString方法 Called puter: 20 拋出 MyException異常類對象,其成員變量 detail=20 MyException[20] 2022年 2月 11日星期五 例: 在定義銀行類時(shí),若取錢數(shù)大于余額則作為異 常處理 (InsufficientFundsException)。 思路: ? 產(chǎn)生異常的條件是余額少于取額,因此是否拋出異常 要先判斷該條件。 ? 確定產(chǎn)生異常的方法,應(yīng)該在取錢方法( withdrawal) 中產(chǎn)生異常 InsufficientFundsException 。 ? 處理異常安排在調(diào)用 withdrawal的時(shí)候,因此 withdrawal方法要聲明異常,由上級方法捕獲并處理。 ? 要定義好自己的異常。 自定義異常類實(shí)例 2022年 2月 11日星期五 public class InsufficientFundsException extends Exception { private Bank excepbank。 private double excepAmount。 InsufficientFundsException(Bank ba, double dAmount) { excepbank = ba。 excepAmoun
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1