Java Code Examples for java.text.ParseException#initCause()

The following examples show how to use java.text.ParseException#initCause() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Time4A   File: SimpleFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public T parse(CharSequence text) throws ParseException {

    ParsePosition pp = new ParsePosition(0);
    T result;

    try {
        result = this.parseInternal(text, pp, null);

        if ((result == null) || (pp.getErrorIndex() > -1)) {
            throw new ParseException("Cannot parse: " + text, pp.getErrorIndex());
        }
    } catch (RuntimeException re) {
        ParseException pe = new ParseException(re.getMessage(), pp.getErrorIndex());
        pe.initCause(re);
        throw pe;
    }

    return result;

}
 
Example 2
Source Project: ant-ivy   File: XmlReportParser.java    License: Apache License 2.0 6 votes vote down vote up
public void parse(File report) throws ParseException {
    if (!report.exists()) {
        throw new IllegalStateException("Report file '" + report.getAbsolutePath()
                + "' does not exist.");
    }

    parser = new SaxXmlReportParser(report);
    try {
        parser.parse();
    } catch (Exception e) {
        ParseException pe = new ParseException("failed to parse report: " + report + ": "
                + e.getMessage(), 0);
        pe.initCause(e);
        throw pe;
    }
}
 
Example 3
Source Project: Time4A   File: SimpleFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public T parse(CharSequence text, RawValues rawValues) throws ParseException {

    if (rawValues == null) {
        throw new NullPointerException("Missing raw values.");
    }

    ParsePosition pp = new ParsePosition(0);
    T result;

    try {
        result = this.parseInternal(text, pp, rawValues);

        if ((result == null) || (pp.getErrorIndex() > -1)) {
            throw new ParseException("Cannot parse: " + text, pp.getErrorIndex());
        }
    } catch (RuntimeException re) {
        ParseException pe = new ParseException(re.getMessage(), pp.getErrorIndex());
        pe.initCause(re);
        throw pe;
    }

    return result;

}
 
Example 4
Source Project: darklaf   File: ColorValueFormatter.java    License: MIT License 5 votes vote down vote up
@Override
public Object stringToValue(final String text) throws ParseException {
    try {
        if (text.isEmpty()) {
            return model.getDefault(fieldIndex);
        }
        if (hex) {
            String hexStr = String.format("%1$-" + getHexLength() + "s", text).replaceAll(" ", "F");
            int r = Integer.valueOf(hexStr.substring(0, 2), 16);
            checkRange(r, 0, 255);
            int g = Integer.valueOf(hexStr.substring(2, 4), 16);
            checkRange(g, 0, 255);
            int b = Integer.valueOf(hexStr.substring(4, 6), 16);
            checkRange(b, 0, 255);
            int alpha = hexStr.length() >= 8
                    ? Integer.valueOf(hexStr.substring(6, 8), 16)
                    : 255;
            checkRange(alpha, 0, 255);
            return new Color(r, g, b, alpha);
        } else {
            int value = Integer.valueOf(text, this.radix);
            int min = model.getMinimum(fieldIndex);
            int max = model.getMaximum(fieldIndex);
            checkRange(value, min, max);
            return value;
        }
    } catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 5
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 6
Source Project: Time4A   File: Duration.java    License: Apache License 2.0 5 votes vote down vote up
private static long parseAmount(
    String period,
    String number,
    int index
) throws ParseException {

    try {
        return Long.parseLong(number);
    } catch (NumberFormatException nfe) {
        ParseException pe = new ParseException(period, index);
        pe.initCause(nfe);
        throw pe;
    }

}
 
Example 7
Source Project: lucene-solr   File: SolrSynonymParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void parse(Reader in) throws IOException, ParseException {
  LineNumberReader br = new LineNumberReader(in);
  try {
    addInternal(br);
  } catch (IllegalArgumentException e) {
    ParseException ex = new ParseException("Invalid synonym rule at line " + br.getLineNumber(), 0);
    ex.initCause(e);
    throw ex;
  } finally {
    br.close();
  }
}
 
Example 8
public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md)
        throws IOException, ParseException {
    try {
        Namespace ns = null;
        if (md instanceof DefaultModuleDescriptor) {
            DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
            ns = dmd.getNamespace();
        }
        XmlModuleDescriptorUpdater.update(
            is,
            res,
            destFile,
            new UpdateOptions().setSettings(IvyContext.getContext().getSettings())
                    .setStatus(md.getStatus())
                    .setRevision(md.getResolvedModuleRevisionId().getRevision())
                    .setPubdate(md.getResolvedPublicationDate()).setUpdateBranch(false)
                    .setNamespace(ns));
    } catch (SAXException e) {
        ParseException pe = new ParseException("exception occurred while parsing " + res, 0);
        pe.initCause(e);
        throw pe;
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example 9
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 10
public static Configuration createConfiguration(String name, String content) throws IOException, ParseException {
    try {
        JFCParserHandler ch = new JFCParserHandler();
        parseXML(content, ch);
        return PrivateAccess.getInstance().newConfiguration(name, ch.label, ch.description, ch.provider, ch.settings, content);
    } catch (IllegalArgumentException iae) {
        throw new ParseException(iae.getMessage(), -1);
    } catch (SAXException e) {
        ParseException pe =  new ParseException("Error reading JFC file. " + e.getMessage(), -1);
        pe.initCause(e);
        throw pe;
    }
}
 
Example 11
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 12
Source Project: JDKSourceCode1.8   File: ValueFormatter.java    License: MIT License 5 votes vote down vote up
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 13
/**
 * Ensures the ANTLR lexer will throw an exception after the first error
 * @param lnvae the lexer exception
 */
@Override
public void recover(LexerNoViableAltException lnvae) {
  CharStream charStream = lnvae.getInputStream();
  int startIndex = lnvae.getStartIndex();
  String text = charStream.getText(Interval.of(startIndex, charStream.index()));

  ParseException parseException = new ParseException("unexpected character '" + getErrorDisplay(text) + "'" +
      " on line (" + _tokenStartLine + ") position (" + _tokenStartCharPositionInLine + ")", _tokenStartCharIndex);
  parseException.initCause(lnvae);
  throw new RuntimeException(parseException);
}
 
Example 14
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 15
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 16
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 17
Source Project: Java8CN   File: ValueFormatter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 18
@Override
public Object stringToValue(String text) throws ParseException {
    try {
        return Integer.valueOf(text, this.radix);
    }
    catch (NumberFormatException nfe) {
        ParseException pe = new ParseException("illegal format", 0);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 19
private void setParseError(String reason, Exception e) throws ParseException {
    ParseException newExc = makeParseException(reason + ": " + e.getMessage());
    newExc.initCause(e);
    throw newExc;
}
 
Example 20
private ParseException newParserException(Exception e) {
    Message.error(e.getMessage());
    ParseException pe = new ParseException(e.getMessage(), 0);
    pe.initCause(e);
    return pe;
}