Java Code Examples for org.apache.commons.lang3.exception.ExceptionUtils#wrapAndThrow()

The following examples show how to use org.apache.commons.lang3.exception.ExceptionUtils#wrapAndThrow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTransmission.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
@Override
public void acquire() {
    lock.lock();
    try {
        acquireCnt++;
        while (!acquirable()) {
            try {
                doWait();
            } catch (InterruptedException e) {
                ExceptionUtils.wrapAndThrow(e);
            }
        }
        onAcquired();
    } finally {
        acquireCnt--;
        lock.unlock();
    }
}
 
Example 2
Source File: RunsUtils.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
protected void onException(Throwable e) {

            if (!this.exception.isInstance(e)) {
                ExceptionUtils.wrapAndThrow(e);
            }
            if (onException != null) {
                onException.accept(e);
            }
        }
 
Example 3
Source File: Runs.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
public static void uncheckDo(RunnableWithError runnable) {
    try {
        runnable.run();
    } catch (Throwable e) {
        ExceptionUtils.wrapAndThrow(e);
    }
}
 
Example 4
Source File: Runs.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
public static <T, E extends Throwable> T uncheckCall(ThrowaleCallable<T, E> callable) {
    try {
        return callable.call();
    } catch (Throwable e) {
        ExceptionUtils.wrapAndThrow(e);
        return null;//不会触发
    }
}
 
Example 5
Source File: PeakTransmission.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
public void waitCompleted() {
    lock.lock();
    try {
        while (acquires != 0) {
            try {
                completed.await();
            } catch (InterruptedException e) {
                ExceptionUtils.wrapAndThrow(e);
            }
        }
    } finally {
        lock.unlock();
    }

}
 
Example 6
Source File: Predicates.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code Predicate},
 *
 * @param <T>                the type of the input to the predicate
 * @param throwablePredicate the predicate that may throw an exception
 * @return the predicate result or {@code null} if exception was thrown
 * @throws NullPointerException if {@code throwablePredicate} is null
 */
public static <T> Predicate<T> uncheck(
        ThrowablePredicate<? super T, Throwable> throwablePredicate) {
    Objects.requireNonNull(throwablePredicate);
    return value -> {
        try {
            return throwablePredicate.test(value);
        } catch (Throwable throwable) {
            ExceptionUtils.wrapAndThrow(throwable);
            //never
            return false;
        }
    };
}
 
Example 7
Source File: Predicates.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code BiPredicate},
 *
 * @param <T,U>                the type of the input to the predicate
 * @param throwableBiPredicate the predicate that may throw an exception
 * @return the predicate result or {@code null} if exception was thrown
 * @throws NullPointerException if {@code throwableBiPredicate} is null
 */
public static <T, U> BiPredicate<T, U> uncheck(
        ThrowableBiPredicate<? super T, ? super U, Throwable> throwableBiPredicate) {
    Objects.requireNonNull(throwableBiPredicate);
    return (t, u) -> {
        try {
            return throwableBiPredicate.test(t, u);
        } catch (Throwable throwable) {
            ExceptionUtils.wrapAndThrow(throwable);
            //never
            return false;
        }
    };
}
 
Example 8
Source File: Suppliers.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code Supplier},
 *
 * @param <T>               the type of the input of the supplier
 * @param throwableSupplier the supplier that may throw an exception
 * @return the supplier result or {@code null} if exception was thrown
 * @throws NullPointerException if {@code throwableSupplier} is null
 */
public static <T> Supplier<T> uncheck(
        ThrowableSupplier<? extends T, Throwable> throwableSupplier) {
    Objects.requireNonNull(throwableSupplier);
    return () -> {
        try {
            return throwableSupplier.get();
        } catch (Throwable throwable) {
            ExceptionUtils.wrapAndThrow(throwable);
            //never
            return null;
        }
    };
}
 
Example 9
Source File: Functions.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code Function},
 *
 * @param <T>               the type of the input of the function
 * @param <R>               the type of the result of the function
 * @param throwableFunction the function that may throw an exception
 * @return the function result or {@code null} if exception was thrown
 * @throws NullPointerException if {@code throwableFunction} is null
 */
public static <T, R> Function<T, R> uncheck(
        ThrowableFunction<? super T, ? extends R, Throwable> throwableFunction) {
    Objects.requireNonNull(throwableFunction);
    return value -> {
        try {
            return throwableFunction.apply(value);
        } catch (Throwable throwable) {
            ExceptionUtils.wrapAndThrow(throwable);
            //never
            return null;
        }
    };
}
 
Example 10
Source File: Functions.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code BiFunction},
 *
 * @param <T>                 the type of the input of the biFunction
 * @param <R>                 the type of the result of the biFunction
 * @param throwableBiFunction the biFunction that may throw an exception
 * @return the biFunction result or {@code null} if exception was thrown
 * @throws NullPointerException if {@code throwableBiFunction} is null
 */
public static <T, U, R> BiFunction<T, U, R> uncheck(
        ThrowableBiFunction<? super T, ? super U, ? extends R, Throwable> throwableBiFunction) {
    Objects.requireNonNull(throwableBiFunction);
    return (t, u) -> {
        try {
            return throwableBiFunction.apply(t, u);
        } catch (Throwable throwable) {
            ExceptionUtils.wrapAndThrow(throwable);
            //never
            return null;
        }
    };
}
 
Example 11
Source File: Consumers.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code Consumer} without catch Throwable.
 *
 * @param <T>               the type of the input to the consumer
 * @param throwableConsumer the consumer that may throw an exception
 * @return a {@code Consumer}
 * @throws NullPointerException if {@code throwableConsumer} is null
 * @see #safe(ThrowableConsumer, Consumer)
 */
public static <T> Consumer<T> uncheck(ThrowableConsumer<? super T, Throwable> throwableConsumer) {
    Objects.requireNonNull(throwableConsumer);
    return value -> {
        try {
            throwableConsumer.accept(value);
        } catch (Throwable ex) {
            ExceptionUtils.wrapAndThrow(ex);
        }
    };
}
 
Example 12
Source File: Consumers.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a safe {@code BiConsumer} without catch Throwable.
 *
 * @param <T>               the type of the first argument to the operation
 * @param <U>               the type of the second argument to the operation
 * @param throwableConsumer the consumer that may throw an exception
 * @return a {@code BiConsumer}
 * @throws NullPointerException if {@code throwableConsumer} is null
 * @see #safe(ThrowableBiConsumer, BiConsumer)
 */
public static <T, U> BiConsumer<T, U> uncheck(ThrowableBiConsumer<? super T, ? super U, Throwable> throwableConsumer) {
    Objects.requireNonNull(throwableConsumer);
    return (t, u) -> {
        try {
            throwableConsumer.accept(t, u);
        } catch (Throwable ex) {
            ExceptionUtils.wrapAndThrow(ex);
        }
    };
}
 
Example 13
Source File: SequenceBuffer.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public SequenceBuffer(Class<T> dataContainer, int bufferSize) {
  numEntries = bufferSize;
  entrySequence = new int[numEntries];
  Arrays.fill(entrySequence, INVALID_SEQUENCE);
  entryData = new Object[numEntries];
  try {
    for (int i = 0; i < numEntries; i++) entryData[i] = dataContainer.newInstance();
  } catch (Throwable t) {
    ExceptionUtils.wrapAndThrow(t);
  }

  sequence = 0;
}