gpt4 book ai didi

java - Java 中的本地化异常

转载 作者:行者123 更新时间:2023-11-30 09:16:52 25 4
gpt4 key购买 nike

我有一个用于验证用户输入的界面。为了验证,我使用了一些标准的 Java validator 和一些自定义的。我的自定义 validator 抛出一个 ParseException 并在出错时显示一条本地化消息。但我不知道Java或第三方库是否也使用本地化消息。

问题:我如何在 catch block 中得到异常是否有本地化消息的提示(标准 Java 方式,而不是自定义异常类/接口(interface))?

最佳答案

您可以简单地使用 getLocalizedMessage() 来显示消息,默认实现只是调用 getMessage()

来自documentation of the Throwable class :

public String getLocalizedMessage()
Creates a localized description of this throwable. Subclasses may override this method in order to produce a locale-specific message. For subclasses that do not override this method, the default implementation returns the same result as getMessage().

关于java - Java 中的本地化异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19245881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com