JAVA-8405: reducing logging for tutorials-build-job

This commit is contained in:
chaos2418
2021-11-18 11:19:23 +05:30
parent 4ca8e7ef23
commit a62c0f3c8b
81 changed files with 715 additions and 126 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 occured : {}", e.getMessage());
}
};
}
@@ -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 occured : {}", exCast.getMessage());
} 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 occured : {}", exCast.getMessage());
} catch (ClassCastException ccEx) {
throw new RuntimeException(ex);
}