Make small improvements to exceptions
This commit is contained in:
parent
77fd6f4be1
commit
e98a07dd5e
|
@ -31,6 +31,13 @@ package com.github.zafarkhaja.semver;
|
||||||
*/
|
*/
|
||||||
public class ParseException extends RuntimeException {
|
public class ParseException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a {@code ParseException} instance with no error message.
|
||||||
|
*/
|
||||||
|
public ParseException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a {@code ParseException} instance with an error message.
|
* Constructs a {@code ParseException} instance with an error message.
|
||||||
*
|
*
|
||||||
|
@ -41,9 +48,30 @@ public class ParseException extends RuntimeException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a {@code ParseException} instance with no error message.
|
* Constructs a {@code ParseException} instance with an error message
|
||||||
|
* and the cause exception.
|
||||||
|
*
|
||||||
|
* @param message the error message
|
||||||
|
* @param cause an exception that caused this exception
|
||||||
*/
|
*/
|
||||||
public ParseException() {
|
public ParseException(String message, UnexpectedCharacterException cause) {
|
||||||
|
super(message);
|
||||||
|
initCause(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the string representation of this exception.
|
||||||
|
*
|
||||||
|
* @return the string representation of this exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
Throwable cause = getCause();
|
||||||
|
String msg = getMessage();
|
||||||
|
if (msg != null) {
|
||||||
|
msg += ((cause != null) ? " (" + cause.toString() + ")" : "");
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
return ((cause != null) ? cause.toString() : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,10 @@ public class UnexpectedTokenException extends ParseException {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String message = String.format("Unexpected token '%s'", unexpected);
|
String message = String.format(
|
||||||
|
"Unexpected token '%s'",
|
||||||
|
unexpected
|
||||||
|
);
|
||||||
if (expected.length > 0) {
|
if (expected.length > 0) {
|
||||||
message += String.format(
|
message += String.format(
|
||||||
", expecting '%s'",
|
", expecting '%s'",
|
||||||
|
|
|
@ -84,7 +84,10 @@ public class UnexpectedElementException extends RuntimeException {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String message = String.format("Unexpected element '%s'", unexpected);
|
String message = String.format(
|
||||||
|
"Unexpected element '%s'",
|
||||||
|
unexpected
|
||||||
|
);
|
||||||
if (expected.length > 0) {
|
if (expected.length > 0) {
|
||||||
message += String.format(
|
message += String.format(
|
||||||
", expecting '%s'",
|
", expecting '%s'",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user