Merge branch 'master' into JAVA-7244-Review_log_statements_for_projects

This commit is contained in:
Loredana Crusoveanu
2021-12-09 10:22:41 +02:00
committed by GitHub
1079 changed files with 12491 additions and 4924 deletions

View File

@@ -1,15 +1,20 @@
package com.baeldung.java8.lambda.exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Consumer;
public class LambdaExceptionWrappers {
private static final Logger LOGGER = LoggerFactory.getLogger(LambdaExceptionWrappers.class);
public static Consumer<Integer> lambdaWrapper(Consumer<Integer> consumer) {
return i -> {
try {
consumer.accept(i);
} catch (ArithmeticException e) {
System.err.println("Arithmetic Exception occured : " + e.getMessage());
LOGGER.error("Arithmetic Exception occurred.", e);
}
};
}
@@ -21,7 +26,7 @@ public class LambdaExceptionWrappers {
} catch (Exception ex) {
try {
E exCast = clazz.cast(ex);
System.err.println("Exception occured : " + exCast.getMessage());
LOGGER.error("Exception occurred.", exCast);
} catch (ClassCastException ccEx) {
throw ex;
}
@@ -46,7 +51,7 @@ public class LambdaExceptionWrappers {
} catch (Exception ex) {
try {
E exCast = exceptionClass.cast(ex);
System.err.println("Exception occured : " + exCast.getMessage());
LOGGER.error("Exception occurred.", exCast);
} catch (ClassCastException ccEx) {
throw new RuntimeException(ex);
}