google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Work.run and VoidWork.vrun should throw Exception or InvocationTargetException. #187

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, one couldn't throw a checked exception from a Work (eg: transaction)

Converting all exceptions to RuntimeException is not the good way, as I want to 
use my exceptions elsewhere too, and I like the extra visibility of checked 
exceptions. It would be better to throw the uncatched exceptions, wrapped 
inside an InvocationTargetException, or even throw them directly.

In java, it's already done, see java.util.concurrent.Callable<V>

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html

version: 4.0rc2

Original issue reported on code.google.com by simplex....@gmail.com on 19 Dec 2013 at 10:53

GoogleCodeExporter commented 9 years ago
Throwing Exception from this interface would force every caller to catch 
Exception (or declare it), making the interface cumbersome to use. 
InvocationTargetException is no better. You get all the pain of checked 
exceptions with none of the type safety; this is the reason checked exceptions 
have been abandoned by pretty much every language designed since Java. Checked 
exceptions are incompatible with the idea of standard interfaces.

You may choose to wrap ObjectifyImpl.transact() with your own method that 
throws Exception; you can use your own unchecked wrapper exception to convey 
the original exception across the Work boundary. But I don't recommend it.

Original comment by lhori...@gmail.com on 23 Dec 2013 at 10:43