Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30197
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Martin Gregorie <martin@address-in-sig.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: redesign exception |
| Date | Mon, 27 Oct 2014 01:05:43 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 94 |
| Message-ID | <m2k5p7$tic$1@dont-email.me> (permalink) |
| References | <c79cbd2e-970b-4cd3-b181-da33bb43c4b6@googlegroups.com> <1d6fc97wumvl6$.316nwmuziazw.dlg@40tude.net> <6e29c258-9842-4c60-9d99-9929a92d7a96@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Mon, 27 Oct 2014 01:05:43 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="30284"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192iLOO4WB4mz1vF8WZXS8WeES58p7pQzA=" |
| User-Agent | Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
| Cancel-Lock | sha1:nRHoRXdNe/p1FoTyIlSbhrurWUE= |
| Xref | csiph.com comp.lang.java.programmer:30197 |
Show key headers only | View raw
On Sun, 26 Oct 2014 12:46:59 -0700, boxzou wrote:
> Here is a JPA exception I once tried to recover from (catch) ('a ->b'
> means b is a cause of a as in exception chaining):
> PersistenceException -> DatabaseException -> BatchUpdateException ->
> SQLIntegrityConstraintViolationException
>
> And in the ultimate cause 'SQLIntegrityConstraintViolationException',
> there is a code 'ORA-00001' which mean unique constraint violated.
>
> So I have to drill down all the way to find the ultimate cause, even on
> that one if I had to make sure, I would have called getCode() to see if
> it is 'ORA-00001'.
>
Yes, you do have to deal with all the exceptions in that list - and its
nothing to do with Java specifically.
You are seeing this exception list because this is the behaviour of every
RDBMS I've used: when an RDBMS throws an exception, that is merely the
head of a list of related exceptions. To properly report what went wrong
you have to work down the list, reporting the exception name and error
message contained in each SQL exception in the list. That is required by
the way that almost every RDBMS works.
Since an ODBC driver is a machine independent RDBMS interface, it follows
that it also reports SQL exceptions by returning a reference to a list of
exceptions. And, since a JDBC driver class follows the ODBC structure
very closely and in many cases is implemented as an ODBC wrapper, it does
the same.
> An if I switch from Oracle DB to Derby DB, the chain of exceptions would
> be:
> PersistenceException -> DatabaseException -> BatchUpdateException ->
> SQLIntegrityConstraintViolationException -> EmbedSQLException ->
> StandardException
>
Of course: Oracle, Derby (and MySQL, MariaDB, PostgreSQL, SQLserver,
Sybase, DB2, HSQL) are independently developed proprietary RDBMS (only
PostgreSQL, HSQL and MariaDB are open source; MySql used to be), so their
implementations are, of course different and so are the exceptions they
throw in similar circumstances.
> Why do we have this kind of chaining? because Java has checked
> exceptions.
>
Bollocks. You see it when using with JDBC or Reflection as RDBMS
interfaces because this is what any RDBMS needs to do if it is to return
an accurate description of what caused an SQL exception.
The *only* place you'll see such a chain in pure Java is
when a higher level class catches an exception thrown by a method of a
lower level class it called and, instead of dealing with the exception
and throwing a more meaningful exception, chooses to build a chain by
throwing an Exception containing its explanation plus a link to the
Exception that it caught. I can't offhand think of many Java standard
library classes that do this, but you *should* look for and follow these
chains wherever they might be found if you use 3rd party class libraries.
Yes, they should document their uses of such Exception chains, but they
may have forgotten to do so. All RDBMS implement such chains and
*document* the fact that they do so it should not come as a surprise.
> But even if we do away with checked exceptions, the
> exception type alone still is not sufficient to handle the exception.
>
Disagree.
Name or code, its utterly irrelevant which you get handed provided its
unique. In C you get a (hopefully unique) exit code and are left to
decide whether you want to handle it of not. In Java, you *must* catch a
checked Exception but its up to you whether you're a lazy wazzock and
deal with all Exceptions in a single portmanteau catch() clause or
whether you are more careful and differentiate their handling with a set
of catch() clauses.
> We still need to get a code to know exactly what happened.
>
Yeah. Its called the Exception name.
> with a code, e.g. unique constraint violated, but which unique
> constraint? The constraint name is buried in the message, which is
> unstructured data. I want structured data.
>
Sorry, but that's not what any RDBMS does. Live with it: its probably[1]
written into the current SQL specification and is not going to change.
[1] 'probably', because the SQL standard is a paid-for document and I
don't have access to a copy.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
redesign exception boxzou@gmail.com - 2014-10-25 19:16 -0700
Re: redesign exception Joerg Meier <joergmmeier@arcor.de> - 2014-10-26 08:09 +0100
Re: redesign exception rossum <rossum48@coldmail.com> - 2014-10-26 09:15 +0000
Re: redesign exception Joerg Meier <joergmmeier@arcor.de> - 2014-10-26 10:36 +0100
Re: redesign exception Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-26 09:23 -0400
Re: redesign exception boxzou@gmail.com - 2014-10-26 12:56 -0700
Re: redesign exception Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-26 18:10 -0400
Re: redesign exception boxzou@gmail.com - 2014-10-26 17:39 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-26 12:06 -0700
Re: redesign exception Joerg Meier <joergmmeier@arcor.de> - 2014-10-26 20:41 +0100
Re: redesign exception boxzou@gmail.com - 2014-10-26 12:46 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-26 13:12 -0700
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-26 16:50 -0500
Re: redesign exception boxzou@gmail.com - 2014-10-26 17:21 -0700
Re: redesign exception Martin Gregorie <martin@address-in-sig.invalid> - 2014-10-27 01:05 +0000
Re: redesign exception boxzou@gmail.com - 2014-10-26 19:38 -0700
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-27 00:13 -0500
Re: redesign exception boxzou@gmail.com - 2014-10-27 04:59 -0700
Re: redesign exception Marketa Jadalova <m-jadalova3@gmail.com> - 2014-10-27 16:55 +0000
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-27 12:46 -0500
Re: redesign exception boxzou@gmail.com - 2014-10-27 15:48 -0700
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-27 22:16 -0500
Re: redesign exception Robert Klemme <shortcutter@googlemail.com> - 2014-10-27 23:54 +0100
Re: redesign exception boxzou@gmail.com - 2014-10-27 17:20 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-28 07:12 -0700
Re: redesign exception Robert Klemme <shortcutter@googlemail.com> - 2014-10-29 08:34 +0100
Re: redesign exception Martin Gregorie <martin@address-in-sig.invalid> - 2014-10-29 11:17 +0000
Re: redesign exception Silvio <silvio@internet.com> - 2014-10-29 15:33 +0100
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-29 11:35 -0500
Re: redesign exception boxzou@gmail.com - 2014-10-29 17:51 -0700
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-29 20:45 -0500
Re: redesign exception boxzou@gmail.com - 2014-10-30 04:12 -0700
Re: redesign exception Silvio <silvio@internet.com> - 2014-10-30 12:38 +0100
Re: redesign exception boxzou@gmail.com - 2014-10-30 06:23 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-29 17:01 -0700
Re: redesign exception Marketa Jadalova <m-jadalova3@gmail.com> - 2014-10-29 16:55 +0000
Re: redesign exception Martin Gregorie <martin@address-in-sig.invalid> - 2014-10-29 17:29 +0000
Re: redesign exception Robert Klemme <shortcutter@googlemail.com> - 2014-10-29 18:59 +0100
Re: redesign exception Martin Gregorie <martin@address-in-sig.invalid> - 2014-10-29 22:05 +0000
Re: redesign exception boxzou@gmail.com - 2014-10-29 18:04 -0700
Re: redesign exception Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-10-29 20:56 -0500
Re: redesign exception boxzou@gmail.com - 2014-10-30 04:19 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-30 04:27 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-30 04:35 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-29 18:01 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-29 17:00 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-29 16:56 -0700
Re: redesign exception boxzou@gmail.com - 2014-10-26 12:52 -0700
Re: redesign exception Silvio <silvio@internet.com> - 2014-10-27 09:03 +0100
Re: redesign exception boxzou@gmail.com - 2014-10-27 05:06 -0700
Re: redesign exception Silvio <silvio@internet.com> - 2014-10-27 13:32 +0100
Re: redesign exception boxzou@gmail.com - 2014-10-27 07:01 -0700
csiph-web