/** * <p>Returns the (zero based) index of the first <code>Throwable</code> * that matches the specified class or subclass in the exception chain. * Subclasses of the specified class do match - see * {@link #indexOfThrowable(Throwable, Class)} for the opposite.</p> * * <p>A <code>null</code> throwable returns <code>-1</code>. * A <code>null</code> type returns <code>-1</code>. * No match in the chain returns <code>-1</code>.</p> * * @param throwable the throwable to inspect, may be null * @param type the type to search for, subclasses match, null returns -1 * @return the index into the throwable chain, -1 if no match or null input * @since 2.1 */ public static int indexOfType(Throwable throwable, Class type) { return indexOf(throwable, type, 0, true); }
/** * <p>Returns the (zero based) index of the first <code>Throwable</code> * that matches the specified class (exactly) in the exception chain. * Subclasses of the specified class do not match - see * {@link #indexOfType(Throwable, Class)} for the opposite.</p> * * <p>A <code>null</code> throwable returns <code>-1</code>. * A <code>null</code> type returns <code>-1</code>. * No match in the chain returns <code>-1</code>.</p> * * @param throwable the throwable to inspect, may be null * @param clazz the class to search for, subclasses do not match, null returns -1 * @return the index into the throwable chain, -1 if no match or null input */ public static int indexOfThrowable(Throwable throwable, Class clazz) { return indexOf(throwable, clazz, 0, false); }
/** * <p>Returns the (zero based) index of the first <code>Throwable</code> * that matches the specified type in the exception chain from * a specified index. * Subclasses of the specified class do match - see * {@link #indexOfThrowable(Throwable, Class)} for the opposite.</p> * * <p>A <code>null</code> throwable returns <code>-1</code>. * A <code>null</code> type returns <code>-1</code>. * No match in the chain returns <code>-1</code>. * A negative start index is treated as zero. * A start index greater than the number of throwables returns <code>-1</code>.</p> * * @param throwable the throwable to inspect, may be null * @param type the type to search for, subclasses match, null returns -1 * @param fromIndex the (zero based) index of the starting position, * negative treated as zero, larger than chain size returns -1 * @return the index into the throwable chain, -1 if no match or null input * @since 2.1 */ public static int indexOfType(Throwable throwable, Class type, int fromIndex) { return indexOf(throwable, type, fromIndex, true); }
/** * <p>Returns the (zero based) index of the first <code>Throwable</code> * that matches the specified type in the exception chain from * a specified index. * Subclasses of the specified class do not match - see * {@link #indexOfType(Throwable, Class, int)} for the opposite.</p> * * <p>A <code>null</code> throwable returns <code>-1</code>. * A <code>null</code> type returns <code>-1</code>. * No match in the chain returns <code>-1</code>. * A negative start index is treated as zero. * A start index greater than the number of throwables returns <code>-1</code>.</p> * * @param throwable the throwable to inspect, may be null * @param clazz the class to search for, subclasses do not match, null returns -1 * @param fromIndex the (zero based) index of the starting position, * negative treated as zero, larger than chain size returns -1 * @return the index into the throwable chain, -1 if no match or null input */ public static int indexOfThrowable(Throwable throwable, Class clazz, int fromIndex) { return indexOf(throwable, clazz, fromIndex, false); }