下面列出了java.text.ParseException#initCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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;
}
}
@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;
}
@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;
}
}
@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;
}
}
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;
}
}
@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();
}
}
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();
}
}
}
@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;
}
}
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;
}
}
@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;
}
}
@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;
}
}
/**
* 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);
}
@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;
}
}
@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;
}
}
@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;
}
}
@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;
}
}
@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;
}
}
private void setParseError(String reason, Exception e) throws ParseException {
ParseException newExc = makeParseException(reason + ": " + e.getMessage());
newExc.initCause(e);
throw newExc;
}
private ParseException newParserException(Exception e) {
Message.error(e.getMessage());
ParseException pe = new ParseException(e.getMessage(), 0);
pe.initCause(e);
return pe;
}