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

正文內容

java程序設計電子教案第五章-資料下載頁

2025-01-01 00:47本頁面
  

【正文】 throws中,并用逗號分割開來。聲明拋出異常類名列表,就使得異常對象可以依次向后查找,直到有合適的方法捕獲他為止。實例見下面“ ”一節(jié)。 ? 在系統(tǒng)不能識別的創(chuàng)建用戶自定義的異常時,需要編程者在程序中合適位置創(chuàng)建自定義異常的對象,并利用 throw語句將這個新異常對象拋出。 上一頁 返回 ? 本例演示了如何對異常條件生成用戶定義的異常類層,和如何用這些用戶定義的異常類編寫程序來處理異常條件。例子的第一部分構造了一個報告年齡相關異常的異常類層,如 圖52所示。 ? 這個層次的根為 AgeException類。它有一個數(shù)據(jù)成員Age,用于防治導致異常發(fā)生的年齡。它有兩個子類:類OutOfAgeLimtException用了對于特定任務年齡太小或太老的情況,而類 IllegalAgeFormatException用于年齡在合法范圍以外或格式有錯誤的情況。前一個類用數(shù)據(jù)成員 age linmit 來設置可接受的年齡極限,定義這些類的程序如下: 下一頁 返回 ? Import java . io .*。 ? Class AgeException extends Exception { ? Int age。 ? AgeException() { ? Super()。 ? } ? AgeException(String message) { ? Super(message)。 ? } ? } 上一頁 下一頁 返回 ? Class OutOfAgeLimtException extends AgeException { ? Int ageLimit。 ? OutOfAgeLimtException extends AgeException { ? Super(message)。 ? } ? OutOfAgeLimtException(int ageLimit,String message){ ? Super(message)。 ? =ageLimit。 ? } ? } 上一頁 下一頁 返回 ? Class Too Young Exception extends OutOfAgeLimtException { ? Too Young Exception() { ? Super(“ too young” )。 ? } ? Too Young Exception(int age,int ageLimit,String message){ ? Super(ageLimit ,” You are too young to” +message +” .” )。 ? This . age=age。 ? } ? } 上一頁 下一頁 返回 ? Class TooOldException extends OutOfAgeLimtException { ? TooOldException() { ? Super(“ too old” )。 ? } ? TooOldException(int age,int ageLimit,String message) { ? Super(ageLimit,” You are too old to” +message +” .” )。 ? =age。 ? } ? } 上一頁 下一頁 返回 ? class IllegalAgeFormatException extends AgeException { ? IllegalAgeFormatException (String message) { ? Super(message)。 ? } ? IllegalAgeFormatException() { ? Super(“ Illegal age format” )。 ? } ? } 上一頁 下一頁 返回 ? Class NegativeAgeExcption extends IllegalAgeFormatException { ? Negative AgeExcption(String message) { ? Super(message)。 ? } ? Negative AgeExcption(int age) { ? Super(“ Age must be nonnegative.” )。 ? =age。 ? } ? } 上一頁 下一頁 返回 ? 例子的第二部分是使用前構造的異常類層的程序。本程序在不同年齡之間循環(huán),看看特定年齡的人能否作過山車。如果年齡太小、太大或是負數(shù),則方法RideRollerCoasterAtAge()會分別拋出 Too Young Exception、 TooOldException和NegativeageExcption。程序列出如下: ? Public class AgeException Test{ ? Static PrintWriter out=new PrintWriter(System . out, true)。 ? Static void rideRollerCoaxterAtAge(int age) ? Throws NetativeAgeExcption,OutOfAgeLimtException { ? Out. printIn(“ Trying to ride a roller coaster at age “ +age+” …” )。 上一頁 下一頁 返回 ? If (age0) ? Throw new Negative AgeExcption(age)。 ? Else if(age5) ? Throw new Too Young Exception(age , 5 ,” ride a roller coaster “ )。 ? Else if(age45) ? Throw nes TooOldException(age ,45 ,” ride a roller coaster” )。 ? Out_printIn(“ Riding the roller coaster…” )。 ? } 上一頁 下一頁 返回 ? Public static void main (String args{}) { ? Int ages{}={3 ,2 ,10 ,35 ,65}。 ? For(int i=0。iages,length。i++) ? Try { ? rideRollerCoasterAtAge(ages[i])。 ? out . printIn(“ Wow!What an experience!” )。 ? }catch(OutOfAgeLimtException e) { ? out . printIn(() )。 上一頁 下一頁 返回 ? if (ages[i]e .ageLimit) ? out . printIn( (ages[i])+” more years and you can try it .” )。 ? else ? out . printIn( (ages[i]) ? +” years ago riding it was like a piece of cake .” )。 ? }catch(Negative AgeExcption e) { ? (() )。 ? }finally{ ? Out. printIn()。 ? } ? } ? } 上一頁 下一頁 返回 ? 上述程序的輸出如下: ? Trying to ride a roller coaster at age 3… ? Age must be nonnegative. ? Trying to ride a roller coaster at ago 2… ? You are too young to ride a roller coaster. ? 3 more years and you’ ll be able to try it. ? Trying to ride a roller coaster at age 10… ? Riding the roller coaster… 上一頁 下一頁 返回 ? Wow! What an wxperience! ? Trying to ride a roller coaste at age 35… ? Riding the roller coaster… ? Wow! What an wxperience! ? Trying to ride a roller coaster at age 65… ? You are too old to ride a roller coaster. ? 20 years ago riding it was like a piece of cake. 上一頁 返回 圖 52 AgeException類的大層次 返回 謝謝觀看 /歡迎下載 BY FAITH I MEAN A VISION OF GOOD ONE CHERISHES AND THE ENTHUSIASM THAT PUSHES ONE TO SEEK ITS FULFILLMENT REGARDLESS OF OBSTACLES. BY FAITH I BY FAITH
點擊復制文檔內容
范文總結相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1