Thought about Exceptions, RxJava and Spring
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 1 Jan 2017 16:23:47 +0000 (17:23 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 1 Jan 2017 16:23:47 +0000 (17:23 +0100)
SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/AwesomeBusinessLogicImpl.java
SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java

index 5c960fe..37da05a 100644 (file)
@@ -21,6 +21,13 @@ public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic {
        
        @Override
        public Page<Car> findAll(Pageable pageRequest) {
+
+               // It seems like calling Exceptions.propagate(ex) in RxJava code is only required
+               // for no RuntimeExceptions (for catchable exceptions)
+               // Spring will see this exception :)
+               // So no catchable exceptions do not require anything at all for being seen by Spring :)
+               // throw new RuntimeException("createThrowable FATAL ERROR");
+
         final List<Car> cars = new ArrayList<>();
         cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 1)));
         cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 2)));
@@ -68,6 +75,8 @@ public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic {
                // Spring sees both exceptions.
                // It seems like calling Exceptions.propagate(ex) in RxJava code is only required
                // for no RuntimeExceptions :/
+               // Spring will see this exception :)
+               // So no catchable exceptions do not require anything at all for being seen by Spring :)
                // throw new RuntimeException("createThrowable FATAL ERROR");
        }
 }
index 771fb40..d18ae31 100644 (file)
@@ -83,6 +83,8 @@ public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic {
                                        
                                        LOGGER.error("createThrowable error: ", ex);
                                        
+                                       // This method is only required when wrapping catchable exceptions.
+                                       // RuntimeExceptions do not require this stuff and they are seen by Spring MVC.
                                        Exceptions.propagate(ex);
                                }