Class ExceptionUtil
java.lang.Object
org.eclipse.rdf4j.federated.exception.ExceptionUtil
Convenience functions to handle exceptions.
- Author:
- Andreas Schwarte
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final Pattern
Regex pattern to identify http error codes from the title of the returned document:Matcher m = httpErrorPattern.matcher("[..] 503 Service Unavailable [..]"); if (m.matches()) { System.out.println("HTTP Error: " + m.group(1); }
protected static final org.slf4j.Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Exception>
EchangeExceptionMessage
(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
static QueryEvaluationException
Converts the given Throwable to aQueryEvaluationException
.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.
-
Field Details
-
log
protected static final org.slf4j.Logger log -
httpErrorPattern
Regex pattern to identify http error codes from the title of the returned document:Matcher m = httpErrorPattern.matcher("[..]
503 Service Unavailable [..]"); if (m.matches()) { System.out.println("HTTP Error: " + m.group(1); }
-
-
Constructor Details
-
ExceptionUtil
public ExceptionUtil()
-
-
Method Details
-
traceExceptionSource
public static QueryEvaluationException traceExceptionSource(Endpoint endpoint, Throwable ex, String additionalInfo) Trace the exception source within the exceptions to identify the originating endpoint. The message of the provided exception is adapted to "@ endpoint.getId() - %orginalMessage".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"
- Parameters:
endpoint
- the the endpointex
- the exceptionadditionalInfo
- additional information that might be helpful, e.g. the subquery- Returns:
- a modified exception with endpoint source
-
traceExceptionSourceAndRepair
public static QueryEvaluationException traceExceptionSourceAndRepair(Endpoint endpoint, Throwable ex, String additionalInfo) Repair the connection and then trace the exception source.- Parameters:
endpoint
-ex
-- Returns:
- the exception
-
getExceptionString
-
changeExceptionMessage
public static <E extends Exception> E changeExceptionMessage(String msgPrefix, E ex, Class<E> exClazz) If possible change the message text of the specified exception. This is only possible if the provided exception has a public constructor with String and Throwable as argument. The new message is set to 'msgPrefix. ex.getMessage()', all other exception elements remain the same.- Type Parameters:
E
-- Parameters:
msgPrefix
-ex
-exClazz
-- Returns:
- the updated exception
-
toException
-
toQueryEvaluationException
Converts the given Throwable to aQueryEvaluationException
. If it is already of typeQueryEvaluationException
no transformation is done, otherwise the throwable is wrapped.- Parameters:
t
-- Returns:
- the
QueryEvaluationException
-