java.lang.Throwable.getLocalizedMessage()%uA0方法创建这个Throwable的本地化描述。子类可以以产生特定于语言环境的消息重写此方法。
声明
以下是java.lang.Throwable.getLocalizedMessage()方法的声明
public String getLocalizedMessage()
参数
-
NA
返回值
此方法返回这个抛出的本地化描述。
异常
-
NA
例子
下面的例子显示java.lang.Throwable.getLocalizedMessage()方法的使用。
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) // 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...