Merge branch 'master' into JAVA-7244-Review_log_statements_for_projects
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ import java.util.function.BiFunction;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MethodReferenceUnitTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MethodReferenceUnitTest.class);
|
||||
|
||||
private static <T> void doNothingAtAll(Object... o) {
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Test
|
||||
public void referenceToStaticMethod() {
|
||||
List<String> messages = Arrays.asList("Hello", "Baeldung", "readers!");
|
||||
@@ -61,7 +63,7 @@ public class MethodReferenceUnitTest {
|
||||
|
||||
@Test
|
||||
public void limitationsAndAdditionalExamples() {
|
||||
createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize()));
|
||||
createBicyclesList().forEach(b -> LOGGER.debug("Bike brand is '{}' and frame size is '{}'", b.getBrand(), b.getFrameSize()));
|
||||
createBicyclesList().forEach((o) -> MethodReferenceUnitTest.doNothingAtAll(o));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user