Even though the catch-clause throws an exception the finally-block
will be run as usual just as if there'd be no catch-clause at all.

What your code is missing is a tx.success() after doSomething(). Also
this code doesn't need the tx.failure() call (since throwing the
exception will make the tx.success() not to be called).

I'd guess you've alreade seen this, but more information is here:
http://wiki.neo4j.org/content/Transactions#Controlling_success

2010/2/23 Rick Bullotta <[email protected]>:
> If an exception cause a block of code to exit prior to a transaction being
> finish()ed, will it be implicitly finished in garbage collection?
>
>
>
> Here's the situation I want to try to implement : I would like to propagate
> the exception thrown by "doSomething()" to the caller of myFunc(), but also
> ensure that the transaction is properly "failed" and the transaction is
> properly "finished", if necessary:
>
>
>
> public void myFunc()  throws Exception {
>
>                Transaction tx    neo.beginTx();
>
>
>
>                try {
>
>                                doSomething();  // This could throw an
> exception
>
>                }
>
>                catch(Exception ex) {
>
>                                tx.failure();
>
>                                throw new Exception("An error has occurred:
> " + ex.getMessage);
>
>                }
>
>                finally{
>
>                                tx.finish();
>
>                }
>
> }
>
>
>
> I think I'm just not thinking clearly since I've been coding for 24 of the
> last 36 hours, so I wanted to see if I'm too tired to figure out what should
> be an easy exception handling scenario.
>
>
>
> Thanks
>
>
>
> Rick
>
>
>
> _______________________________________________
> Neo mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Mattias Persson, [[email protected]]
Neo Technology, www.neotechnology.com
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to