Class ExceptionUtil


  • public class ExceptionUtil
    extends Object
    Convenience functions to handle exceptions.
    Author:
    Andreas Schwarte
    • 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); }
    • Constructor Detail

      • ExceptionUtil

        public ExceptionUtil()
    • 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 endpoint
        ex - the exception
        additionalInfo - 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