在Java編程中,如何傳遞參數給拋出已檢查異常?
此示例顯示如何使用catch
塊處理已檢查的異常。
package com.zaixian;
public class PassArgumentException {
public static void main(String args[]) {
try {
throw new Exception("throwing an exception");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
上述代碼示例將產生以下結果 -
throwing an exception