语法public throwable getcause()
示例public class getcausemethodtest { public static void main(string[] args) throws exception { try { myexception(); } catch(exception e) { system.out.println("cause = " + e.getcause()); } } public static void myexception() throws exception { int arr[] = {1, 3, 5}; try { system.out.println(arr[8]); } catch(arrayindexoutofboundsexception aiobe) { exception e = new exception(); throw(exception); // throwing the exception to be caught by catch block in main() e.initcause(aiobe); // supplies the cause to getcause() } }}
输出cause = java.lang.arrayindexoutofboundsexception: 8
以上就是在java中,getcause()方法的重要性是什么?的详细内容。
