Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30205
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2014-10-27 07:01 -0700 |
| References | <c79cbd2e-970b-4cd3-b181-da33bb43c4b6@googlegroups.com> <544dfc54$0$2842$e4fe514c@news.xs4all.nl> <9c03f8fd-587e-4112-ad08-6d10017ebe0b@googlegroups.com> <544e3b57$0$2922$e4fe514c@news.xs4all.nl> |
| Message-ID | <e02b0706-3d31-4136-9763-06b4ba71dec8@googlegroups.com> (permalink) |
| Subject | Re: redesign exception |
| From | boxzou@gmail.com |
> case SQLException(14) => println("SQL error 14")
This is very close to what I want. It would be better if we don't have to write any extractor at all.
Fault(FaultCode code, String...args): args is varargs, the length is validated against numArgs in FaultCode.
FaultCode(String code, int numArgs, String messageTemplate).
Scala is a very interesting language. Competition drives innovation.
Thanks.
On Monday, 27 October 2014 08:32:32 UTC-4, Silvio wrote:
> Were SQLException a Scala case class or would someone add an extractor
> after the fact (which you can easily do yourself without breaking
> anything) that would become:
>
> case SQLException(14) => println("SQL error 14")
> case SQLException(15) => println("SQL error 15")
> case SQLException(x) => println("SQL errror " + x)
>
> where the latter would match any SQL exception extracting the number into x.
>
> This is all about language, nothing else. Standardization on exception
> will not happen simply because there is no fixed format to catch all
> imaginable types of exceptions in. Exceptions in general can not be
> brought down to 1, 2 or any n fixed fields or values.
>
> A language like Scala however, allows you to write such extractors for
> any given set of exception types that are relevant to your code.
>
> A language designed for extensibility allows you to define this without
> having to change the language itself. Among others Scala is such a
> language, Java is not. Pattern matching is just an example but there is
> plenty more.
>
>
> On 10/27/2014 01:06 PM, box...@gmail.com wrote:
> > What I'd really like to achieve is to be able to say:
> >
> > case x : java.sql.SQLException.14
> >
> > Language does not matter. The problem I posted about is across all OO languages.
> >
> > Other points:
> > 1. standardize the details as parameters
> > 2. documentation and I18N support through messageTemplate.
> >
> > The new exception handling mechanism can be added in a backward compatible manner so nothing would be broken.
> >
> > The current way one public class per Java file has its advantage: so easy to search for a class.
> >
> > On Monday, 27 October 2014 04:03:43 UTC-4, Silvio wrote:
> >> Simply switch to Scala's exception syntax and most of your problem goes
> >> away:
> >>
> >> try
> >> {
> >> // something dangerous
> >> }
> >> catch
> >> {
> >> case x : java.sql.SQLException if x.getErrorCode() == 14 => // SQL 14
> >> case x : Exception => println(x.getMessage)
> >> }
> >>
> >> Scala extends its pattern matching syntax to handle exceptions. If you
> >> define your user exceptions as case classes (special type of class that
> >> automagically has extended support for pattern matching) you can not
> >> only catch cases based on class and an if-clause but specify any pattern
> >> that Scala pattern matching supports.
> >>
> >> This not only allows more fine-grained handling but also enables you to
> >> extract exception fields/details while matching. Too much to summarize
> >> here, I suggest you look into Scala pattern matching.
> >>
> >> Oh, and in Scala you can put as many classes in a source as you want.
> >> That might be a nice change to Java as well...
> >>
> >> Then again, as a variation on a common saying: if it's too much broken
> >> don't fix it...
> >>
Back to comp.lang.java.programmer | Previous | Next — Previous 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