From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,61e9062c1f23b9d5 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!newsfeed2.telusplanet.net!newsfeed.telus.net!edtnps82.POSTED!53ab2750!not-for-mail Sender: blaak@METROID Newsgroups: comp.lang.ada Subject: contracted exceptions (was Re: Reconsidering assignment) References: <1181165630.012508.55290@i38g2000prf.googlegroups.com> <19fxsxv1god43$.1pqq8vgfu2itn$.dlg@40tude.net> From: Ray Blaak Message-ID: Organization: The Transcend User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 07 Jun 2007 16:54:34 GMT NNTP-Posting-Host: 154.20.94.243 X-Trace: edtnps82 1181235274 154.20.94.243 (Thu, 07 Jun 2007 10:54:34 MDT) NNTP-Posting-Date: Thu, 07 Jun 2007 10:54:34 MDT Xref: g2news1.google.com comp.lang.ada:16092 Date: 2007-06-07T16:54:34+00:00 List-Id: "Dmitry A. Kazakov" writes: > I would like to see contracted exceptions... The Java experience shows that compiler checked exception specifications don't work. It sounds good in theory, but in practice programmers tend to write unnecessary try/catch handlers that result in the worst possible outcome, and in fact the exact opposite of what exception specs were intended for: exceptions get ignored without changing control flow. A typical naive programmer, forced by the compiler to handle an exception, overwhelmingly seems to do: try { doSomething(); } catch (SomeError e) { e.printStackTrace(); } or even worse: try { doSomething(); } catch (SomeError e) { } And the program continues on its merry way. Slightly more aware programmers tend to do: void doManyThings() throws ManyErrors { try { doSomething(); } catch (SomeError e) { throw new ManyErrors(e); } } I.e. they carefully catch all errors and rethrow according to the contract of their current method. This results in substantial portions of code that is simply mechanical tedious try/catch/rethrow clutter. If one observes what actually is needed for exception processing it tends to be: a) abort control flow - the current op cannot proceed. b) report the error to the user in a central way (in a popup, via a log, whatever), and either exit or wait for the next new input/action. This means that in practice one does not actually need to handle exceptions at all. Handling exceptions actually becomes the "exception" not the rule, so to speak. So, use unchecked exceptions, throw away all those try/catch handlers, and the code gets cleaned up, and is actually safer. It is also safer for newbie programmers: they will no longer be forced to handle anything, and so their default action will actually be correct. C# got it right, and all its exceptions are unchecked. I have done significant C# projects, and it works well. My current Java code is now everywhere always of the form: void doIt() throws Exception which allows all exceptions to quietly go everywhere. -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, rAYblaaK@STRIPCAPStelus.net The Rhythm has my soul.