Java Throwable initCause()方法與示例

Throwable類initCause()方法 (Throwable Class initCause() method)

  • initCause() Method is available in java.lang package.

    initCause()方法在java.lang包中可用。

  • initCause() Method is used to instantiate the cause of this throwable to the given value and this method is invoked within the constructor immediately after that we throw a throwable object.

    initCause()方法用于將此throwable的原因實例化為給定值,并且在我們拋出throwable對象之后立即在構造函數中調用此方法。

  • initCause() Method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    initCause()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • initCause() Method may throw an exception at the time of initializing cause.

    initCause()方法可能會在初始化原因時引發異常。

    • IllegalArgumentException – This exception may throw when the given argument is this object.IllegalArgumentException-如果給定參數是此對象,則可能引發此異常。
    • IllegalStateException – This exception may throw when the given argument was created with throwable or when this method called already on this throwable.IllegalStateException-當使用throwable創建給定參數時,或者在此throwable上已調用此方法時,可能會拋出此異常。

Syntax:

句法:

    public Throwable initCause(Throwable caus);

Parameter(s):

參數:

  • Throwable caus – represents the cause it retrieve by using getCause() method and if it returns null then cause is non-existent or not known.

    可拋出的原因-表示使用getCause()方法檢索的原因,如果返回null,則原因不存在或未知。

Return value:

返回值:

The return type of the method is Throwable, it returns reference to this "Throwable" object.

方法的返回類型為Throwable ,它返回對此“ Throwable”對象的引用。

Example:

例:

// Java program to demonstrate the example 
// of Throwable initCause(Throwable caus)
// method of Throwable 
public class InitCause {
public static void main(String args[]) throws Exception {
try {
// calling div() method
div(100, 0);
} catch (ArithmeticException ex) {
// Display the exception cause why it is
//thrown
System.out.println("Exception Cause:" + ex.getCause());
}
}
// This method divide two numbers and will
// throw an exception
public static void div(int d1, int d2) throws Exception {
try {
int res = d1 / d2;
} catch (ArithmeticException ex) {
// creating an exception
ArithmeticException ae = new ArithmeticException();
// instantiate exception cause by using
//initCause() method
ae.initCause(ex);
// throw an exception with its cause
throw (ae);
}
}
}

Output

輸出量

Exception Cause:java.lang.ArithmeticException: / by zero

翻譯自: https://www.includehelp.com/java/throwable-initcause-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541507.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541507.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541507.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mysql 存儲過程死循環_pl/sql存儲過程loop死循環

今早,一個存儲過程,寫過很多次的存儲過程,隨手一寫,各種報錯,各種糾結,網上一搜,有好多個都遇到,論壇上給出的結局答案,今早,一個存儲過程,寫過很…

GATK之VariantAnnotator

VariantAnnotator 簡要說明 用途: 利用上下文信息注釋識別的變異位點(variant calls)分類: 變異位點操作工具概要: 根據變異位點的背景信息(與功能注釋相對)進行注釋。目前有許多的注釋模塊(見注釋模塊一節…

pipedreader_Java PipedReader connect()方法與示例

pipedreaderPipedReader類的connect()方法 (PipedReader Class connect() method) connect() method is available in java.io package. connect()方法在java.io包中可用。 connect() method is used to cause this PipedReader to be connected to the given PipedWriter (sou…

《Java學習指南》—— 1.4 設計安全

本節書摘來異步社區《Java學習指南》一書中的第1章,第1.4節,作者:【美】Patrick Niemeyer , Daniel Leuck,更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 1.4 設計安全 Java被設計為一種安全語言,對于這一事實…

ppython_Python pcom包_程序模塊 - PyPI - Python中文網

PCOM在python中一個非常基本的unitronics pcom協議實現。如何使用from pcom import commandsfrom pcom.plc import EthernetPlcwith EthernetPlc(address(192.168.5.43, 1616)) as plc:# Read realtime clockc commands.ReadRtc()res plc.send(c)print(res)# Set realtime cl…

bitcount方法詳解_Java Long類的bitCount()方法和示例

bitcount方法詳解長類bitCount()方法 (Long class bitCount() method) bitCount() method is available in java.lang package. bitCount()方法在java.lang包中可用。 bitCount() method is used to find the number of 1s bits in the 2s complement binary denotation of the…

《軟件定義數據中心:Windows Server SDDC技術與實踐》——導讀

前言 通過對自身的審視和對身邊IT 技術專家的觀察,我發現對于我們來說,掌握一項新的技術或熟悉一個新的產品,大都是聞而后知,知而后學,學以致用,用以知其然。然而Windows Server作為一個簡單的、易上手的操…

python二維向量運算模擬_python二維向量運算_[VB.NET][C#]二維向量的基本運算

前言在數學中,幾何向量是指具有大小和方向的幾何對象。在編程中,向量有著廣泛的應用,其作用在圖形編程和游戲物理引擎方面尤為突出。第一節 構造函數通過創建一個二維向量的類(或結構體),實現向量的表示及其運算。1. 首先&#xf…

Java LinkedHashMap clear()方法與示例

LinkedHashMap類的clear()方法 (LinkedHashMap Class clear() method) clear() method is available in java.util package. clear()方法在java.util包中可用。 clear() method is used to remove all the existing elements from this LinkedHashMap. clear()方法用于從此Link…

《Imperfect C++中文版》——1.3 運行期契約:前置條件、后置條件和不變式

本節書摘來自異步社區出版社《Imperfect C中文版》一書中的第1章,第1.3節,作者: 【美】Matthew Wilson,更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 1.3 運行期契約:前置條件、后置條件和不變式 Imperfect …

python名稱空間與運用域_Python名稱空間和作用域講座,命名,Namespaces,Scopes

Python命名空間(Namespaces)和作用域(Scopes)講座命名空間(Namespace)命名空間(Namespace),是名稱到對象的映射。命名空間提供了在項目中避免名字沖突的一種方法。命名空間是獨立的,沒有任何關系的,所以一個命名空間中不能有重名,…

getminimum_Java Calendar getMinimum()方法與示例

getminimumCalendar類的getMinimum()方法 (Calendar Class getMinimum() method) getMinimum() method is available in java.util package. getMinimum()方法在java.util包中可用。 getMinimum() method is used to get the minimum value of the given field(fi) of this Cal…

《Spark核心技術與高級應用》——3.2節構建Spark的開發環境

本節書摘來自華章社區《Spark核心技術與高級應用》一書中的第3章,第3.2節構建Spark的開發環境,作者于俊 向海 代其鋒 馬海平,更多章節內容可以訪問云棲社區“華章社區”公眾號查看 3.2 構建Spark的開發環境無論Windows或Linux操作系統&am…

python閉包怎么理解_Python 閉包的理解

Last Updated on 2019年10月15日Python中的閉包是一個比較模糊的概念,不太好理解,我最近的面試中也被問及,在一個單例模式的實現上,我用裝飾器實現單例,然后面試官就問到了我對閉包的理解,回答的不太清楚。…

Java BufferedReader mark()方法與示例

BufferedReader類mark()方法 (BufferedReader Class mark() method) mark() method is available in java.io package. mark()方法在java.io包中可用。 mark() method is used to mark the current position in this stream and whenever we call reset() method so it will re…

《全球互聯網金融商業模式:格局與發展》——第3章,第3節互聯網保險公司...

本節書摘來自華章出版社《全球互聯網金融商業模式:格局與發展》一書中的第3章,第3.3節互聯網保險公司,作者廖理,更多章節內容可以訪問云棲社區“華章計算機”公眾號查看 3.3 互聯網保險公司互聯網思維貫穿整個保險創新發展過程&a…

webapi隨機調用_BeetleX之webapi驗證插件JWT集成

對于webapi服務應用很多時候需要制訂訪問限制,在前面的章節也講述了組件如何制訂控制器訪問控制;但到了實際應用要自己去編寫還是比較麻煩。為了讓訪問控制更方便組件實現基于JWT的控制器訪問控制組件BeetleX.FastHttpApi.Jwt;通過這個組件可…

java bitset_Java BitSet nextClearBit()方法與示例

java bitsetBitSet類nextClearBit()方法 (BitSet Class nextClearBit() method) nextClearBit() method is available in java.util package. nextClearBit()方法在java.util包中可用。 nextClearBit() method is used to retrieve the index of the first bit that is set to …

《馴獅記——Mac OS X 10.8 Mountain Lion使用手冊》——2.3 Dock

本節書摘來自異步社區《馴獅記——Mac OS X 10.8 Mountain Lion使用手冊》一書中的第2章,第2.3節,作者:陳明 , 張錚 , 馬玉龍著,更多章節內容可以訪問云棲社區“異步社區”公眾號查看 2.3 Dock 馴獅記——Mac OS X 10.8 Mountain…

mysql 嵌套if標簽_對比Excel、MySQL、Python,分別講述 “if函數” 的使用原理!

作者:黃偉呢本文轉自:數據分析與統計學之美其實,不管是Excel、MySQL,還是Python,“if”條件判斷都起著很重要的作用。今天這篇文章,就帶著大家盤點一下,這三種語言如何分別使用 “if函數” 。if…