Throwable.getLocalizedMessage() 方法
描述
java.lang.Throwable.getLocalizedMessage() 方法创建这个 throwable 的本地化描述。 子类可以覆盖此方法以生成特定于语言环境的消息。
声明
以下是 java.lang.Throwable.getLocalizedMessage() 方法的声明。
public String getLocalizedMessage()
参数
NA
返回值
此方法返回此 throwable 的本地化描述。
异常
NA
示例
下面的例子展示了 java.lang.Throwable.getLocalizedMessage() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class ThrowableDemo {
public static void main(String[] args) throws Throwable {
try {
newException();
} catch(Throwable e) {
System.err.println(e);
// localized description of this throwable
System.out.println(e.getLocalizedMessage());
}
}
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...

