java.lang.Throwable.getCause()方法实例

java.lang.Throwable.getCause()方法实例

width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_0" name="aswift_0" style="box-sizing: border-box; left: 0px; position: absolute; top: 0px;">
id="iframeu1064372_0" src="http://pos.baidu.com/ockm?rdid=1064372&dc=2&di=u1064372&dri=0&dis=0&dai=1&ps=377x246&dcb=BAIDU_SSP_define&dtm=HTML_POST&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1476164655511&ti=java.lang.Throwable.getCause()%E6%96%B9%E6%B3%95%E5%AE%9E%E4%BE%8B%20-%20java.lang&ari=2&dbv=2&drs=1&pcs=907x692&pss=978x1661&cfv=0&cpl=5&chi=1&cce=true&cec=UTF-8&tlm=1476164655&rw=709&ltu=http%3A%2F%2Fwww.yiibai.com%2Fjava%2Flang%2Fthrowable_getcause.html&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D3W4yzl3fJ4OtMJTaZ5jb9QBZppYJ8cLphGgJWm_4wXPVK7DzrEcZtY4WRn2lPltjdM6U0DlQ1NBBa1XZM26LuFl2J9hKUaVJcZ_rbTJBITS%26wd%3D%26eqid%3Dc164818e0000a54c0000000557fc7c2c&ecd=1&psr=1920x1080&par=1920x1040&pis=-1x-1&ccd=24&cja=false&cmi=7&col=zh-CN&cdo=-1&tcn=1476164656&qn=1495bcb21fe3c5c6&tt=1476164655492.22.346.353" width="728" height="90" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: border-box; border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">

Windows10用户联盟QQ群: 227270512


 java.lang.Throwable.getCause() 方法返回此抛出或空的原因,如果原因不存在或未知

声明

以下是java.lang.Throwable.getCause()方法的声明

public Throwable getCause()

参数

  • NA

返回值

此方法返回此抛出或空的原因,如果原因不存在或未知。

异常

  • NA

例子

下面的例子显示java.lang.Throwable.getCause()方法的使用。

package com.yiibai;

import java.lang.*;

public class ThrowableDemo {

   public static void main(String[] args) throws Throwable {

     try {
        newException();
     }
     catch(Throwable e) {
        System.err.println(e);
        // returns null as the cause is nonexistent or unknown.
        System.err.println("Cause = " + e.getCause());
     }
   }
  
   public static void newException() throws Exception {
      System.out.println("This is newException() function");
      throw new Exception("Exception...");
   }
}
 

让我们来编译和运行上面的程序,这将产生以下结果:

This is newException() function
java.lang.Exception: Exception...
Cause = null

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值