Are there any best-practice solutions (patterns?) for this problem? I
would be happy about some links to examples or discussions.
If you're interesting in some controversial reading or discussions...
It should be noted that there are a lot of Real World [TM]
applications powering, well, pretty much the entire
Real World [TM] that are developed in languages that do not
have the SNAFU concept of checked/unchecked exceptions.
The almighty Joshua Bloch has quite a lot to say on checked
exceptions. For a start, "prefer state testing methods to
checked exceptions".
Lots of food for thoughts in that advice and, of course,
that's how things are done in languages that do not have
the concept of checked exceptions.
If you're interested in views that are unlikely to be
found entertaining in this group, a lot of people consider
checked exception to be GOTO programming.
As an example, we're working on a medium sized codebase
(it's not the Eclipse codebase but it's not either dad & mom's
petstore app) here: a client/server app whose client app
is deployed daily on hundreds of new machines.
The client side app is mostly Java (about 1% of native code)...
The number of checked exceptions we defined in our codebase?
Zero.
Once again, if GOTO-style checked exceptions were mandatory
to be able to develop applications, how would people coding
in languages not supporting checked exceptions do their work?
Food for thought I tell you:
Joshua Bloch: "Prefer state testing methods to checked exceptions".
Why do we define zero checked exceptions? Well, simply because
they don't exist at the OOA/OOD level.
We provide OO abstractions and we translate our OOA/OOD to
Java using only (Java) interfaces.
'Checked exceptions' represent nothing at that level.
People using them are cornering themselves in some Javaites
details that shouldn't exist.
Result? Impossible to port and GOTO-like spaghetti codebase.
Btw I've also worked for a company that wrote an automated
solution for porting applications to hundreds of mobile
devices. We translated Java to Objective-C code automatically
and have published apps on the Apple appstore that reached
the top ten where we wrote exactly *zero* line of Objective-C
code. It was all automated translation. Having a clean
OOA/OOD and straightforward OOD -> OOP that do not rely on
"Javaites" helped a lot of course
Now there's something else... You're talking about rollbacks
and it screams famous RDBs.
OO and RDB don't mix well: they're mostly orthogonal concepts.
And CRUD sucks big times. The next thing is CRA
People and companing working as Java/SQL plumbers have cornered
themselves in one field of the computer industry, Ted Newards
make a very good writing on the subject that gained quite a lot
of traction:
"Object-Relational mapping is the Vietnam of our industry"
If you're interested in reading and discussions, that's a good one.
Did I mention that in addition to using zero checked exceptions
we're using an OO DB?
So, using broken APIs that forces you to do GOTO-style programming
because they know knowing about neither good practices, nor OO, sure,
sometimes you're forced to because you can't do otherwise.
But then of course you can ditch such crappy APIs and go use
APIs and framework from people who "saw the light".
The Spring dudes, for example, puke on checked exceptions because
they're, well, a Gosling brainfart...
From the Spring doc:
"Again in keeping with Spring's philosophy, the ...Exception that
"can be thrown by any of the ... interface's methods is unchecked"
*is unchecked*
That's the Spring philosophy. That's the way to do it.
80's GOTO programming should be dead (it ain't but it should be).
Spring's doc also states that: "JTA is a cumbersome API to use
(partly due to its exception model)"
Do like us, stand on the shoulder of giants.
Listen to what Joshua Bloch says, read about Spring, read on OO.
Take everything written in c.l.j.p. with a grain of salt because
most posters here tend to consider every Gosling brain fart to be
the holy gospel
P.S: Lew the grammar nazi can go talk to his psychiatrist about
my grammar and spelling mistakes (not native english speaker here)