/** * Remove the exception factory method from the stack trace. The factory is not the place where * the failure occurs; the error occurs in the factory's caller. * * @param factory The name of the factory method. * @param exception The exception to trim. * @return {@code exception} for convenience. */ private static ParseException trim(final String factory, final ParseException exception) { StackTraceElement[] trace = exception.getStackTrace(); if (trace != null && trace.length != 0) { if (factory.equals(trace[0].getMethodName())) { trace = XArray.remove(trace, 0, 1); exception.setStackTrace(trace); } } return exception; }
adjusted.setStackTrace(exception.getStackTrace()); adjusted.initCause(exception.getCause()); throw adjusted;
@SuppressWarnings(value={"unchecked"}) private String convertXmlToJson(String xmlToConvert) throws ParseException { if (xmlToConvert == null) { throw new ParseException("Unable to convert XML to JSON", 0); } try { String xmlWithoutBreaks = removeLineBreaks(xmlToConvert); byte[] xmlByteArray = xmlWithoutBreaks.getBytes(); Configuration config = new Configuration(); if (null != namespaces && !namespaces.isEmpty()) { config.getXmlToJsonNamespaces().putAll(namespaces); } ByteArrayInputStream source = new ByteArrayInputStream(xmlByteArray); AbstractXMLOutputFactory writerFactory = new MappedXMLOutputFactory(config); ByteArrayOutputStream output = serialise(source, writerFactory); return new String(output.toByteArray()); } catch (IOException e) { ParseException ex = new ParseException("Unable to convert XML to JSON", 0); ex.setStackTrace(e.getStackTrace()); throw ex; } }
p.setStackTrace(e.getStackTrace()); throw p;