[rules-users] Some Code Problem about SingleSessionCommandService

Esteban Aliverti esteban.aliverti at gmail.com
Mon Nov 15 07:00:38 EST 2010


For you, maybe t1 is more important than t2, but for someone else perhaps t2
is more important than t1. I don't know which solution is better, but right
now, t1 is being logged and t2 is being thrown.
Here is the Jira issue: https://jira.jboss.org/browse/JBRULES-2656

<https://jira.jboss.org/browse/JBRULES-2656>Best,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


2010/11/14 Rui Tang <tangrui at zyeeda.com>

> Hi list,
>
> During my application development, I encountered some problems about the
> exception handling within SingleSessionCommandService class.
>
> In this constructor
>
>     public SingleSessionCommandService(KnowledgeBase kbase,
>                                        KnowledgeSessionConfiguration conf,
>                                        Environment env) {
>
> the exceptions are handled like this
>
> try {
>     ....
> }  catch ( Exception t1 ) {
>     try {
>         this.txm.rollback(); // line 1
>     } catch ( Throwable t2 ) {
>         throw new RuntimeException( "Could not commit session or rollback",
> t2 ); // line 2
>     }
>     throw new RuntimeException( "Could not commit session", t1 ); // line 3
> }
>
> In the first try block, if some exception occurred, exception t1 will be
> caught, then this.txm (TransactionManager) will be rolled back. But during
> this piece of code, if exception occurred again, throwable t2 will be
> caught, then t2 will be wrapped into another runtime exception and re-throw.
> In this case the wrapped t1 (in line 3) will never be throw out. But in my
> situation, the wrapped t1 exception will be more meaningful than the wrapped
> t2 exception.
>
> So I think this code should be changed like this:
>
> try {
>     ...
> } catch (Exception t1) {
>     try {
>         this.txm.rollback();
>     } catch (Throwable t2) {
>         logger.error(t2.getMessage(), t2); // or some other logs, but do
> NOT rethrow
>     }
>     throw new RuntimeException( "Could not commit session", t1
> }
>
> Is this right?
> --
> 唐睿
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101115/5f9e7845/attachment.html 


More information about the rules-users mailing list