国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

面向對象(throws和throw的區別)

2019-11-14 21:14:57
字體:
來源:轉載
供稿:網友
面向對象(throws和throw的區別)

/** * Created by Administrator on 2014/9/29. * * throws和throw的區別 * * throws使用在函數上,throw使用在函數內 * * throws后面跟的是異常類,可以跟多個,用逗號連接 * throw后面跟的是異常對象 */ //copyright?liupengcheng //http://m.survivalescaperooms.com/liupengcheng class fushuException extends Exception {     PRivate int value;     fushuException(String msg,int value)     {         super(msg);         this.value = value;     }     public int getValue()     {         return value;     } }

//copyright?liupengcheng //http://m.survivalescaperooms.com/liupengcheng

class Demo5 {     int div(int a,int b)    throws fushuException //fushuException    自定義負數異常     {         if(b<0)             throw new fushuException("出現了除數是負數的情況",b);         return a/b;     } }

//copyright?liupengcheng //http://m.survivalescaperooms.com/liupengcheng

public class ExceptionDemo3 {     public static void main(String [] args)     {         Demo5 d = new Demo5();         try         {             int x = d.div(4,-1);             System.out.println("x"+ x);         }         catch(fushuException e)         {             System.out.println(e.toString());             System.out.println("出現問題的數值是"+ e.getValue());         }

        System.out.println("over");     } }

//copyright?liupengcheng //http://m.survivalescaperooms.com/liupengcheng


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉林市| 临清市| 浦江县| 根河市| 房产| 浦东新区| 巴林左旗| 南涧| 旌德县| 兰坪| 新野县| 南江县| 桑日县| 开鲁县| 托克托县| 台北县| 永泰县| 台山市| 浦江县| 揭东县| 神农架林区| 崇义县| 浪卡子县| 乐昌市| 马公市| 西峡县| 开封市| 霍州市| 乳山市| 富阳市| 康保县| 仙游县| 芦溪县| 岫岩| 武威市| 兴国县| 华坪县| 文山县| 驻马店市| 古交市| 建阳市|