THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block |
---|
try { code...; } catch (Exception specific to your code) { Specific exception handling and logging... } catch (Exception e) { s_logger.warn("Caught unexpected exception", e); exception handling code... } |
Code Block |
---|
try { code...; } catch (XenAPIException e) { // Do either this: s_logger.warn("Caught a xen api exception", e); // or throw new CloudRuntimeException("Caught a xen api exception", e); // Don't ever do JUST this. throw new CloudRuntimeException("Got a xen api exception"); } |
Code Block |
---|
public void irresponsibleMethod() throws Exception; public void responsibleMethod() throws XenAPIException; public void runtimeExceptMethod(); // throws CloudRuntimeException that's not suppose to be logged until entry point. public void innocentCaller() { try { irresponsibleMethod(); responsibleMethod(); runtimeExceptionMethod(); } catch(Exception e) { s_logger.warn("Unable to execute", e); throw new CloudRuntimeException("Unable to execute", e); // What's wrong here? // 1. If the error was thrown from responsibleMethod, the caller now forgot to do special handling for XenAPIException. // 2. If the error was thrown from runtimeExceptionMethod, the caller now log it once here, and will log again at entry point. } } |
Code Block |
---|
try { some code; } catch(XenAPIException e) { // catch generic error here. s_logger.debug("There's an exception. Rolling back code: " + e.getMessage()); ...rollback some code; throw e; // note there's no "new" here. } |
Code Block |
---|
for (Task task : taskList) { try { process task; } catch (Exception e) { ...handle exception and continue } } |
...