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

The following examples show how to use java.text.ParseException#initCause() . 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 File: SimpleFormatter.java    From Time4A with 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 File: SimpleFormatter.java    From Time4A with 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 3
Source File: XmlReportParser.java    From ant-ivy with 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 4
Source File: ValueFormatter.java    From JDKSourceCode1.8 with 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 5
Source File: ValueFormatter.java    From hottub with GNU General Public License v2.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 6
Source File: ValueFormatter.java    From Java8CN with 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 7
Source File: ValueFormatter.java    From openjdk-jdk9 with GNU General Public License v2.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 8
Source File: ValueFormatter.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 9
Source File: ValueFormatter.java    From openjdk-jdk8u with GNU General Public License v2.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 10
Source File: JavascriptErrorHandlingLexer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: ColorValueFormatter.java    From darklaf with 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 12
Source File: ValueFormatter.java    From TencentKona-8 with GNU General Public License v2.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 13
Source File: JFCParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: ValueFormatter.java    From jdk8u_jdk with GNU General Public License v2.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 15
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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 16
Source File: SolrSynonymParser.java    From lucene-solr with 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 17
Source File: Duration.java    From Time4A with 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 18
Source File: ValueFormatter.java    From jdk1.8-source-analysis with 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 19
Source File: CollationRuleParser.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
private void setParseError(String reason, Exception e) throws ParseException {
    ParseException newExc = makeParseException(reason + ": " + e.getMessage());
    newExc.initCause(e);
    throw newExc;
}
 
Example 20
Source File: PomModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private ParseException newParserException(Exception e) {
    Message.error(e.getMessage());
    ParseException pe = new ParseException(e.getMessage(), 0);
    pe.initCause(e);
    return pe;
}