日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java中什么是运行异常_在java中最常用的运行时异常是什么?

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java中什么是运行异常_在java中最常用的运行时异常是什么? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我從不會拋出NullPointerException。對我來說,它是一個出現在代碼中當出現問題時,需要開發人員看看會發生什么。然后(s)他固定的原因,它不會再次發生。

我使用IllegalStateException表示對象配置不正確或調用的順序不正確。但是,我們都知道,理想情況下,一個對象應該確保它不能處于壞的狀態,你不能以錯誤的順序調用它(使一個構建器和一個結果對象…)。

當一個方法檢測到其參數不正確時,我使用了很多IllegalArgumentException。這是任何公共方法的責任,停止處理(以避免更難以理解的間接錯誤)。另外,在方法開始的幾個ifs提供文檔目的(文檔從不偏離代碼,因為它是代碼:-))。

public void myMethod(String message, Long id) {

if (message == null) {

throw new IllegalArgumentException("myMethod's message can't be null");

// The message doesn't log the argument because we know its value, it is null.

}

if (id == null) {

throw new IllegalArgumentException("myMethod's id can't be null");

// This case is separated from the previous one for two reasons :

// 1. to output a precise message

// 2. to document clearly in the code the requirements

}

if (message.length()<12) {

throw new IllegalArgumentException("myMethod's message is too small, was '" + message + "'");

// here, we need to output the message itself,

// because it is a useful debug information.

}

}

我還使用特定的運行時異常來表示更高級別的異常條件。

For example, if a module of my application couldn’t start, I might have a ModuleNotOperationalException thrown (ideally by a generic code like an interceptor, otherwise by a specific code) when another module calls it. After that architectural decision, each module has to deal with this exception on operations that call other modules…

總結

以上是生活随笔為你收集整理的java中什么是运行异常_在java中最常用的运行时异常是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。