org.eclipse.rdf4j.federated.exception

## 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 and 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 and Description
    `ExceptionUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <E extends Exception> E` | `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)` Converts the `Throwable` to an `Exception`.
    `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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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

    - #### toException

          public static Exception toException(Throwable t)

      Converts the `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.
      Parameters:
        `t` -
      Returns:
        the `Exception`

    - #### toQueryEvaluationException

          public static QueryEvaluationException toQueryEvaluationException(Throwable t)

      Converts the given Throwable to a `QueryEvaluationException`. If it is already of type `QueryEvaluationException` no transformation is done, otherwise the throwable is wrapped.
      Parameters:
        `t` -
      Returns:
        the `QueryEvaluationException`

Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.