[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: Justification for

scott.stark@jboss.org do-not-reply at jboss.com
Thu Jul 27 13:31:36 EDT 2006


"timfox" wrote : Wouldn't it be better if the method is written to always guarantee to leave the object in a well defined state?
  | 
  | If the object is not left in a well defined state then even if you catch Throwable, then there's not much you can do since you don't know if the underlying resource (or whatever) was actually allocated.
  | 
  | ...
  | 
  | Then your're not leaving anything to chance and you can avoid throws Throwable.
  | 
  | This is mentioned in Bloch's effective Java "Strive for failure atomicity"
  | 
  | What am I missing?
  | 

You have made an assumption that all Throwables map to an IllegalStateException and that the actual type of the exception event is not relevant to the caller's state machine with respect to how it relates to obtaining a connection. I would miss the opportunity to have different transitions for different types of exception events:


  | 
  | {
  |    Connection conn = null;
  | 
  |    try
  |    {
  | 
  |       log.info("before allocation");
  | 
  |       conn = ......
  | 
  |       log.info("after allocation");
  |    }
  |    catch(NoRouteToHostException e)
  |    {
  | ...
  |    }
  |    catch(OutOfMemoryError e)
  |    {
  | ...
  |    }
  |    catch (Throwable t)
  |    {
  |       if (conn != null) conn.close();
  |       // Why should I throw away the type and prevent my caller from doing fine-grained event handling?
  |       throw new IllegalStateException();
  |    }
  | 
  | }
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961365#3961365

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961365



More information about the jboss-dev-forums mailing list