本文整理汇总了Java中javax.xml.stream.XMLStreamException.getNestedException方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamException.getNestedException方法的具体用法?Java XMLStreamException.getNestedException怎么用?Java XMLStreamException.getNestedException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamException
的用法示例。
在下文中一共展示了XMLStreamException.getNestedException方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleStreamException
import javax.xml.stream.XMLStreamException; //导入方法依赖的package包/类
private static JAXBException handleStreamException(XMLStreamException e) {
// StAXStreamConnector wraps SAXException to XMLStreamException.
// XMLStreamException doesn't print its nested stack trace when it prints
// its stack trace, so if we wrap XMLStreamException in JAXBException,
// it becomes harder to find out the real problem.
// So we unwrap them here. But we don't want to unwrap too eagerly, because
// that could throw away some meaningful exception information.
Throwable ne = e.getNestedException();
if(ne instanceof JAXBException) {
return (JAXBException)ne;
}
if(ne instanceof SAXException) {
return new UnmarshalException(ne);
}
return new UnmarshalException(e);
}
示例2: testXMLResolver
import javax.xml.stream.XMLStreamException; //导入方法依赖的package包/类
@Test
public void testXMLResolver() {
try {
XMLInputFactory xifactory = XMLInputFactory.newInstance();
xifactory.setProperty(XMLInputFactory.RESOLVER, new MyStaxResolver());
File file = new File(getClass().getResource("XMLResolverTest.xml").getFile());
String systemId = file.toURI().toString();
InputStream entityxml = new FileInputStream(file);
XMLStreamReader streamReader = xifactory.createXMLStreamReader(systemId, entityxml);
while (streamReader.hasNext()) {
int eventType = streamReader.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
eventType = streamReader.next();
if (eventType == XMLStreamConstants.CHARACTERS) {
String text = streamReader.getText();
Assert.assertTrue(text.contains("replace2"));
}
}
}
} catch (XMLStreamException ex) {
if (ex.getNestedException() != null) {
ex.getNestedException().printStackTrace();
}
// ex.printStackTrace() ;
} catch (Exception io) {
io.printStackTrace();
}
}