Java中的異常機制

2021-09-12 19:24:44 字數 1044 閱讀 1841

exception又分為執行時異常(runtime exception)和受檢查的異常(checked exception )。

jvm預設處理異常的機制

程式設計師自己處理

``(1) 注意一:try語句塊不可以省略,catch/finally語句塊至少二取其一,可以兩個都要

(2) 注意二:try……catch……finally 語句中可以巢狀try……catch……finally 語句。

public

class

userloginauthenticationtexception

extends

runtimeexception

public

userloginauthenticationtexception

(string message,

string currentoperation)

public

userloginauthenticationtexception

(string arg0,

throwable arg1,

boolean arg2,

boolean arg3)

public

userloginauthenticationtexception

(string message,

throwable cause)

public

userloginauthenticationtexception

(string message)

public

userloginauthenticationtexception

(throwable cause)

public

void

setcurrentoperation

(string currentoperation)

}

Java異常捕獲機制中的finally

package day08 finally塊 finally塊定義在異常捕獲機制的最後 可以直接跟在try塊之後或最後乙個catch塊之後。finally塊中的 一定會執行,無論try塊中的 是否丟擲異常。所以通常會把釋放資源等操作放在finally中,例如關閉流等。author kaixu pub...

java基礎 異常機制

異常基本通過以下兩種方式來處理 1.try catch finally 一般採用本方式,捕獲異常,自己處理 try catch filenotfoundexception e2 finally2.throws 不負責任的做法,將異常直接丟擲,讓別人處理 public static void nofi...

java中關於異常機制的認知和隨感

突然發現好久沒有寫部落格了。雖然是感覺沒有什麼好寫的,但其實深究其原因還不是自己懶 或是自己最近沒有學到什麼像樣子的技術?這乙個月中,我學習到的東西也不能說沒有。其中dubbo,zookeeper,對異常的加深,前端的一些小知識,算是有點可圈可點之處。算了,廢話不多說了,直接進入主題吧,這篇文章沒有...