如何禁用Java中显示的致命错误?
我想知道是否可以禁用 [致命错误]:1:50:在我的Java程序中,PublicId和SystemID之间需要白色空间。错误。
我使用Java内置DOM Parser API来解析XML文档。 XML文档故意不正确,因为我想学习如何处理与XML解析有关的异常。我还想说,当XML文档正确时,没有例外。
我已经尝试了以下内容:
try {
Document doc = documentBuilder.parse(xmlDocument)
} catch (Throwable t){
System.out.println("An error occur when parsing");
}
正确显示捕获块内部的代码,但仍显示致命错误消息。
如果有人有解决方案,我会很高兴,谢谢。
I would like to know if it is possible to disable the [Fatal Error]:1:50: White spaces are required between publicId and systemId. error in my java program.
Im using java built-in DOM parser api to parse an XML document. The xml document is deliberately incorrect because I want to learn how to handle exceptions related to xml parsing. I also want to say that when the xml document is correct, no exception occurs.
I have already tried with the following :
try {
Document doc = documentBuilder.parse(xmlDocument)
} catch (Throwable t){
System.out.println("An error occur when parsing");
}
The code inside the catch block is displayed correctly but the fatal error message is still showing.
If anyone has a solution, I would be delighted, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是默认情况下,错误处理程序对于XML解析器将错误打印到输出。您可以安装自己的处理程序以捕获或忽略错误:
使用如下:
您还可以有一个错误处理程序,例如,在成员变量中将列表存储在列表中,因此您可以在解析后访问它们并检查它们文档。
这是一个完整的示例:
The problem is that by default the error handler for the XML parser prints the errors to the output. You can install your own handler to capture or ignore the errors:
Use it as follows:
You could also have an error handler that, for example, stored the exceptions in lists in member variables, so you could access them and examine them after parsing the document.
Here's a fully worked-out example: