From: Robert Varga Date: Fri, 14 Feb 2014 23:08:05 +0000 (+0100) Subject: Do not catch Throwables, but rather Exceptions X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~320^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=bfa2b4e3f1a93b97a7f4575116e67a2d20b53c75;hp=94b968f7454a2d677b1ac8fc4a81c10ecca03fa3 Do not catch Throwables, but rather Exceptions 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 --- diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java index 204bf1d131..e07c7ed6ac 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java @@ -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 { diff --git a/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java b/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java index 805f5be296..9ef56e5dc4 100644 --- a/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java @@ -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());