Class ExceptionUtil
- java.lang.Object
-
- org.eclipse.rdf4j.federated.exception.ExceptionUtil
-
public class ExceptionUtil extends Object
Convenience functions to handle exceptions.- Author:
- Andreas Schwarte
-
-
Field Summary
Fields Modifier and Type Field Description protected static Pattern
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); }
protected static org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description ExceptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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
toException(Throwable t)
static QueryEvaluationException
toQueryEvaluationException(Throwable t)
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 Detail
-
log
protected static final org.slf4j.Logger log
-
httpErrorPattern
protected static final Pattern 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); }
-
-
Method Detail
-
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
public static String getExceptionString(String msg, Throwable ex)
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
public static Exception toException(Throwable t)
Converts theThrowable
to 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
public static QueryEvaluationException toQueryEvaluationException(Throwable t)
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
-
-