目录

String getMessage()

描述 (Description)

java.lang.Throwable.getMessage()方法返回此throwable的详细消息字符串。

声明 (Declaration)

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

public String getMessage()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回此Throwable实例的详细消息字符串(可以为null)。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.Throwable.getMessage()方法的用法。

package com.iowiki;
import java.lang.*;
public class ThrowableDemo {
   public static void main(String[] args) throws Throwable {
     try {
         newException();
      } catch(Throwable e) { 
         System.err.println(e);
         // returns the detail message string of this Throwable instance 
         System.out.println(e.getMessage());
      }
   }
   public static void newException() throws Exception {
      System.out.println("This is newException() function");
      throw new Exception("new Exception...");
   }
} 

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

This is newException() function
new Exception...
java.lang.Exception: new Exception...
↑回到顶部↑
WIKI教程 @2018