String getLocalizedMessage()
描述 (Description)
java.lang.Throwable.getLocalizedMessage()方法创建此throwable的本地化描述。 子类可以重写此方法以生成特定于语言环境的消息。
声明 (Declaration)
以下是java.lang.Throwable.getLocalizedMessage()方法的声明
public String getLocalizedMessage()
参数 (Parameters)
NA
返回值 (Return Value)
此方法返回此throwable的本地化描述。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.Throwable.getLocalizedMessage()方法的用法。
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);
// 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...