Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33604

Re: Java Checked Exception is BAD!

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Java Checked Exception is BAD!
Date 2016-02-04 18:04 -0500
Organization A noiseless patient Spider
Message-ID <n90l8f$kiu$1@dont-email.me> (permalink)
References (2 earlier) <56b382dd$0$23867$e4fe514c@news.xs4all.nl> <b77a7d7f-5628-4900-a507-736a8354a381@googlegroups.com> <56b3ae12$0$23750$e4fe514c@news.xs4all.nl> <n90bej$a07$1@dont-email.me> <56b3b67e$0$23868$e4fe514c@news.xs4all.nl>

Show all headers | View raw


On 2/4/2016 3:37 PM, Silvio wrote:
> On 02/04/2016 09:16 PM, Eric Sosman wrote:
>> On 2/4/2016 3:01 PM, Silvio wrote:
>>> [...]
>>> The current consensus is that "fail fast and hard" is mostly better than
>>> laborious attempts for partial repairs at various levels. Checked
>>> exceptions promote the latter and make the former very hard.
>>
>>      "Fail fast and hard" is a consensus?  Since when?
>>
>>      Long years ago (before Java, even before C was well-known), I worked
>> on air traffic control systems.  "Fail fast and hard" was not an option,
>> not nohow.
>>
>>      Today, people are developing software for the self-driving car you
>> may buy in a year or two.  Would you encourage them to "Fail fast and
>> hard" while that car is carrying you along the Autobahn?
>>
>>      Perhaps Java is banned from nuclear plants not because of problems
>> with the language, but because it attracts people with ideas like yours.
>>
>
> Exceptions where initially meant to handle, well, exceptional cases.
> Things like program bugs, configuration errors or unexpected hardware
> failure. ClassNotFoundException makes sense, FileNotFoundException is
> moronic.

     Thank you for using rational argument instead of loaded terms.

     "File not found" is surely a condition that can occur, and if it
occurs it certainly could cause the failure of an attempted operation
on the non-existent file.  As such, the condition must be reported in
some fashion.  The two I know of are to return a special value (maybe
null, maybe something like an Optional<Stream>) or to throw an exception
(checked or unchecked).

     C takes the special value approach, and we've all seen how very
successful that's been in getting C programmers to check for failures!
Throwing an exception has several advantages -- the traceback alone is
an enormous benefit -- and throwing a checked exception prevents the
programmer from ignoring the possibility of failure.  Admittedly, Java
cannot force the programmer to do a good job of dealing with failure;
the empty catch block is always possible, as is the catch block with
something silly inside.  In my opinion (which, unlike the O.P., I do
not call "proof"), a programmer who is prompted to consider strange
outcomes will handle them better than someone allowed to ignore them.

     I'll admit that exceptions are no cure-all.  There's the annoying
problem of catching an exception, trying to clean up afterward, and
getting additional exceptions during the cleanup -- the whole business
of "suppressed exceptions" seems awkward at best.  And there's always
room for debate about which exceptions (in which circumstances!) should
be checked and which unchecked; UncheckedIOException demonstrates that
there is no one hard-and-fast rule for resolving the question.  Still,
"It is less than perfect" is no synonym for "it is BAD!"

> And I hope you know that fail fast does not mean that a total system
> should exit and print an error code. It means that it is best to have a
> failure somewhere deep inside a code branch promote fast and loud to a
> suitable high level where there is enough information to decide what to do.

     ... which is precisely what throwing an exception accomplishes.  The
level that has "enough" knowledge can catch it and cope, while the less
well-informed layers can just pass it along.

> If a sensor in my self-driving car is broken I want it to stop instead
> of going faster and faster because you attempted to handle a
> BrokenSpedometerException by returning a harmless zero.

     You're on the Autobahn at the average speed of 142 km/h (88 mph,
see Wikipedia for citation), and if you "fail fast and hard" it will
be your final failure.  See that eighteen-wheeler behind you?  It'll
soon be atop you.

     Besides, who said anything about a "harmless zero?"  I want the
car to detect the broken speedometer and then *do something* about it.
Ignoring it is no good, "fail hard and fast" is also no good.  There
must be code to *cope* with the exceptional condition.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 07:18 -0800
  Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-04 08:15 -0800
    Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-04 17:57 +0100
      Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-04 10:09 -0800
        Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-04 21:01 +0100
          Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-04 12:14 -0800
          Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-04 15:16 -0500
            Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-04 21:37 +0100
              Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-04 13:08 -0800
                Re: Java Checked Exception is BAD! 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-04 21:16 +0000
                Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-04 13:28 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-04 23:11 +0000
                Re: Java Checked Exception is BAD! a.laforgia@gmail.com - 2016-02-05 04:21 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-05 13:07 +0000
              Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-04 18:04 -0500
                Re: Java Checked Exception is BAD! Gene Wirchenko <genew@telus.net> - 2016-02-05 11:40 -0800
          Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-04 23:22 +0100
          Re: Java Checked Exception is BAD! ruben <ceo@iran.gov> - 2016-02-15 11:45 +0000
      Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 11:57 -0800
        Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-04 21:07 +0100
    Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 11:10 -0800
      Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-04 11:28 -0800
        Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 11:33 -0800
          Re: Java Checked Exception is BAD! 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-04 21:08 +0000
          Re: Java Checked Exception is BAD! Lew <lewbloch@gmail.com> - 2016-02-04 16:09 -0800
  Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-04 12:00 -0500
  Re: Java Checked Exception is BAD! Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-02-04 19:28 +0100
    Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 11:15 -0800
      Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-04 14:51 -0500
  Re: Java Checked Exception is BAD! 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-04 21:07 +0000
    Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 14:36 -0800
      Re: Java Checked Exception is BAD! a.laforgia@gmail.com - 2016-02-05 05:28 -0800
  Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 15:31 -0800
    Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-05 08:20 -0500
      Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-05 08:25 -0800
        Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-05 08:47 -0800
          Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-05 16:09 -0800
            Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-06 08:38 -0500
              Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-06 14:13 +0000
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-06 15:23 +0100
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-07 14:49 +0100
                Re: Java Checked Exceptions Robert Klemme <shortcutter@googlemail.com> - 2016-02-07 21:55 +0100
                Re: Java Checked Exceptions boxzou@gmail.com - 2016-02-07 14:39 -0800
                Re: Java Checked Exceptions Robert Klemme <shortcutter@googlemail.com> - 2016-02-08 13:30 +0100
                Re: Java Checked Exceptions boxzou@gmail.com - 2016-02-08 06:14 -0800
                Re: Java Checked Exceptions Robert Klemme <shortcutter@googlemail.com> - 2016-02-08 20:55 +0100
                Re: Java Checked Exceptions Lew <lewbloch@gmail.com> - 2016-02-08 16:06 -0800
                Re: Java Checked Exceptions boxzou@gmail.com - 2016-02-08 18:38 -0800
                Re: Java Checked Exceptions Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-09 12:15 +0000
                Re: Java Checked Exceptions boxzou@gmail.com - 2016-02-09 04:59 -0800
                Re: Java Checked Exceptions Lew <lewbloch@gmail.com> - 2016-02-10 12:13 -0800
                Re: Java Checked Exceptions boxzou@gmail.com - 2016-02-10 19:00 -0800
                Re: Java Checked Exceptions Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-11 12:18 +0000
                Re: Java Checked Exceptions leif.roar@dimnakorr.com - 2016-02-11 04:43 -0600
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 14:34 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 14:11 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-07 23:19 +0000
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 15:42 -0800
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-06 09:43 -0500
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 14:14 -0800
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-08 09:22 -0500
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 11:01 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 11:08 -0800
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-08 22:02 +0100
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 14:09 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-07 23:29 +0000
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-08 21:49 +0100
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-08 17:23 -0500
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 18:46 -0800
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-09 08:21 +0100
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-09 04:58 -0800
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-09 08:17 -0500
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-09 07:57 -0800
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-10 02:37 +0100
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-10 18:58 -0800
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-11 08:13 -0500
                Re: Java Checked Exception is BAD! Lew <lewbloch@gmail.com> - 2016-02-11 14:02 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-11 16:41 -0800
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-10 02:31 +0100
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-10 18:47 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-09 12:26 +0000
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-09 04:57 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-09 18:27 +0000
              Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 20:19 -0800
            Re: Java Checked Exception is BAD! Robert Klemme <shortcutter@googlemail.com> - 2016-02-06 16:01 +0100
              Re: Java Checked Exception is BAD! 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-06 15:10 +0000
                Re: Java Checked Exception is BAD! Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2016-02-06 17:59 -0800
                Re: Java Checked Exception is BAD! 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-07 09:34 +0000
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 14:23 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 20:52 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 21:13 -0800
              Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-07 14:19 -0800
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-07 23:42 +0000
                Re: Java Checked Exception is BAD! Robert Klemme <shortcutter@googlemail.com> - 2016-02-08 13:17 +0100
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 04:39 -0800
                Re: Java Checked Exception is BAD! Lew <lewbloch@gmail.com> - 2016-02-08 16:05 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 18:35 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 19:10 -0800
                Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-08 19:12 -0800
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-11 16:37 +0100
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-11 12:00 -0500
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-11 19:01 +0100
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-11 20:32 +0100
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-11 15:20 -0500
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-11 23:53 +0100
                Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-11 18:21 -0500
                Re: Java Checked Exception is BAD! Lew <lewbloch@gmail.com> - 2016-02-11 15:45 -0800
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-12 01:19 +0100
                Re: Java Checked Exception is BAD! Lew <lewbloch@gmail.com> - 2016-02-11 19:18 -0800
                Re: Java Checked Exception is BAD! Sebastian <news@seyweiler.dyndns.org> - 2016-02-12 08:31 +0100
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-12 15:33 +0100
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-12 15:41 +0100
                Re: Java Checked Exception is BAD! Silvio <silvio@internet.com> - 2016-02-12 15:42 +0100
                Re: Java Checked Exception is BAD! Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-08 21:19 +0000
        Re: Java Checked Exception is BAD! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-05 13:00 -0500
  Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 15:51 -0800
    Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 15:59 -0800
      Re: Java Checked Exception is BAD! boxzou@gmail.com - 2016-02-04 16:03 -0800
    Re: Java Checked Exception is BAD! Eric Douglas <e.d.programmer@gmail.com> - 2016-02-05 05:33 -0800
  Re: Java Checked Exception is BAD! Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2016-02-04 21:05 -0800
  Re: Java Checked Exception is BAD! ynseo <yeori.seo@gmail.com> - 2016-02-08 01:05 -0800
  Re: Java Checked Exception is BAD! Sebastian <sebastian.millies@softwareag.com> - 2016-02-19 03:43 -0800

csiph-web