Provide semantically meaningful exceptions for translation
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -5,34 +5,37 @@
|
||||
|
||||
package com.wireguard.config;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* An exception representing a failure to parse an element of a WireGuard configuration. The context
|
||||
* for this failure can be retrieved with {@link #getContext}, and the text that failed to parse can
|
||||
* be retrieved with {@link #getText}.
|
||||
*/
|
||||
public class ParseException extends Exception {
|
||||
private final String context;
|
||||
private final Class<?> parsingClass;
|
||||
private final CharSequence text;
|
||||
|
||||
public ParseException(final String context, final CharSequence text, final String message) {
|
||||
super(message);
|
||||
this.context = context;
|
||||
public ParseException(final Class<?> parsingClass, final CharSequence text,
|
||||
@Nullable final String message, @Nullable final Throwable cause) {
|
||||
super(message, cause);
|
||||
this.parsingClass = parsingClass;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public ParseException(final String context, final CharSequence text, final Throwable cause) {
|
||||
super(cause.getMessage(), cause);
|
||||
this.context = context;
|
||||
this.text = text;
|
||||
public ParseException(final Class<?> parsingClass, final CharSequence text,
|
||||
@Nullable final String message) {
|
||||
this(parsingClass, text, message, null);
|
||||
}
|
||||
|
||||
public ParseException(final String context, final CharSequence text) {
|
||||
this.context = context;
|
||||
this.text = text;
|
||||
public ParseException(final Class<?> parsingClass, final CharSequence text,
|
||||
@Nullable final Throwable cause) {
|
||||
this(parsingClass, text, null, cause);
|
||||
}
|
||||
|
||||
public String getContext() {
|
||||
return context;
|
||||
public ParseException(final Class<?> parsingClass, final CharSequence text) {
|
||||
this(parsingClass, text, null, null);
|
||||
}
|
||||
|
||||
public Class<?> getParsingClass() {
|
||||
return parsingClass;
|
||||
}
|
||||
|
||||
public CharSequence getText() {
|
||||
|
||||
Reference in New Issue
Block a user