本文整理匯總了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();
}
}