Class ExceptionUtil
java.lang.Object
org.eclipse.rdf4j.federated.exception.ExceptionUtil
Convenience functions to handle exceptions.
- Author:
- Andreas Schwarte
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final PatternRegex 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
Constructors -
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 StringgetExceptionString(String msg, Throwable ex) Return the exception in a convenient representation, i.e.static Exceptionstatic QueryEvaluationExceptionConverts the given Throwable to aQueryEvaluationException.static QueryEvaluationExceptiontraceExceptionSource(Endpoint endpoint, Throwable ex, String additionalInfo) Trace the exception source within the exceptions to identify the originating endpoint.static QueryEvaluationExceptiontraceExceptionSourceAndRepair(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
Return the exception in a convenient representation, i.e. '%msg% (%CLASS%): %ex.getMessage()%'- Parameters:
msg-ex-- Returns:
- the exception in a convenient representation
-
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
Converts theThrowableto anException. If it is already of type exception, it is returned as is. Otherwise, we create a newQueryEvaluationException, and attach the stack trace and a meaningful message.- Parameters:
t-- Returns:
- the
Exception
-
toQueryEvaluationException
Converts the given Throwable to aQueryEvaluationException. If it is already of typeQueryEvaluationExceptionno transformation is done, otherwise the throwable is wrapped.- Parameters:
t-- Returns:
- the
QueryEvaluationException
-