Do not catch Throwables, but rather Exceptions 39/5339/6
authorRobert Varga <rovarga@cisco.com>
Fri, 14 Feb 2014 23:08:05 +0000 (00:08 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 19 Mar 2014 13:06:00 +0000 (13:06 +0000)
This turns catch Throwable into catch Exception, as doing the former
catches Errors, which are documented to be pretty much irrecoverable
conditions. Looking at
http://docs.oracle.com/javase/7/docs/api/java/lang/Error.html non of
these call sites can recover from an Error happening, so they should
never catch them.

Change-Id: I85237594f307a5a8778fb5a63f9dad4d120fc9d7
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java
opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java

index 204bf1d13194800e8a9347e97e97c2959ce9417f..e07c7ed6ac901156aa2d6c23a75114bd523584da 100644 (file)
@@ -109,8 +109,8 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser
                                 netconf_ssh_output.setDaemon(false);
                                 netconf_ssh_output.start();
 
-                            } catch (Throwable t){
-                                logger.error("SSH bridge couldn't create echo socket",t.getMessage(),t);
+                            } catch (Exception t) {
+                                logger.error("SSH bridge could not create echo socket: {}", t.getMessage(), t);
 
                                 try {
                                     if (netconf_ssh_input!=null){
@@ -129,7 +129,6 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser
                                     Thread.currentThread().interrupt();
                                     logger.error("netconf_ssh_output join error ",e);
                                 }
-
                             }
                         } else {
                             try {
index 805f5be29601dcc8026d980b577e69af6758e7f1..9ef56e5dc440b612f5f70e0ec823fca3172aad2c 100644 (file)
@@ -114,6 +114,8 @@ public class BridgeDomainNorthbound {
            if (status.getCode().equals(StatusCode.SUCCESS)) {
                return Response.status(Response.Status.CREATED).build();
            }
+       } catch (Error e) {
+           throw e;
        } catch (Throwable t) {
            return Response.status(Response.Status.PRECONDITION_FAILED).build();
        }
@@ -161,7 +163,7 @@ public class BridgeDomainNorthbound {
           if (status.getCode().equals(StatusCode.SUCCESS)) {
               return Response.status(Response.Status.OK).build();
           }
-      } catch (Throwable t) {
+      } catch (Exception t) {
           return Response.status(Response.Status.PRECONDITION_FAILED).build();
       }
       throw new ResourceNotFoundException(status.getDescription());
@@ -215,7 +217,7 @@ public class BridgeDomainNorthbound {
            if (status.getCode().equals(StatusCode.SUCCESS)) {
                return Response.status(Response.Status.CREATED).build();
            }
-       } catch (Throwable t) {
+       } catch (Exception t) {
            return Response.status(Response.Status.PRECONDITION_FAILED).build();
        }
        throw new ResourceNotFoundException(status.getDescription());
@@ -264,7 +266,7 @@ public class BridgeDomainNorthbound {
            if (status.getCode().equals(StatusCode.SUCCESS)) {
                return Response.status(Response.Status.OK).build();
            }
-       } catch (Throwable t) {
+       } catch (Exception t) {
            return Response.status(Response.Status.PRECONDITION_FAILED).build();
        }
        throw new ResourceNotFoundException(status.getDescription());