public class ExceptionUtil extends Object
Modifier and Type | Field and Description |
---|---|
protected static Pattern |
httpErrorPattern
Regex pattern to identify http error codes from the title of the returned document:
Matcher m = httpErrorPattern.matcher("[..] |
protected static org.slf4j.Logger |
log |
Constructor and Description |
---|
ExceptionUtil() |
Modifier and Type | Method and Description |
---|---|
static <E extends Exception> |
changeExceptionMessage(String msgPrefix,
E ex,
Class<E> exClazz)
If possible change the message text of the specified exception.
|
static String |
getExceptionString(String msg,
Throwable ex)
Return the exception in a convenient representation, i.e.
|
static Exception |
toException(Throwable t)
|
static QueryEvaluationException |
toQueryEvaluationException(Throwable t)
Converts the given Throwable to a
QueryEvaluationException . |
static QueryEvaluationException |
traceExceptionSource(Endpoint endpoint,
Throwable ex,
String additionalInfo)
Trace the exception source within the exceptions to identify the originating endpoint.
|
static QueryEvaluationException |
traceExceptionSourceAndRepair(Endpoint endpoint,
Throwable ex,
String additionalInfo)
Repair the connection and then trace the exception source.
|
protected static final org.slf4j.Logger log
protected static final Pattern httpErrorPattern
Matcher m = httpErrorPattern.matcher("[..] 503 Service Unavailable [..]");
if (m.matches()) {
System.out.println("HTTP Error: " + m.group(1);
}
public static QueryEvaluationException traceExceptionSource(Endpoint endpoint, Throwable ex, String additionalInfo)
Note that in addition HTTP error codes are extracted from the title, if the exception resulted from an HTTP error, such as for instance "503 Service unavailable"
endpoint
- the the endpointex
- the exceptionadditionalInfo
- additional information that might be helpful, e.g. the subquerypublic static QueryEvaluationException traceExceptionSourceAndRepair(Endpoint endpoint, Throwable ex, String additionalInfo)
endpoint
- ex
- public static String getExceptionString(String msg, Throwable ex)
msg
- ex
- public static <E extends Exception> E changeExceptionMessage(String msgPrefix, E ex, Class<E> exClazz)
E
- msgPrefix
- ex
- exClazz
- public static Exception toException(Throwable t)
Throwable
to an Exception
. If it is already of type exception, it is returned as is.
Otherwise, we create a new QueryEvaluationException
, and attach the stack trace and a meaningful message.t
- Exception
public static QueryEvaluationException toQueryEvaluationException(Throwable t)
QueryEvaluationException
. If it is already of type
QueryEvaluationException
no transformation is done, otherwise the throwable is wrapped.t
- QueryEvaluationException
Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.