Why exceptions for error handling is so important

Russel Winder via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 13 07:34:37 PST 2015


On Tue, 2015-01-13 at 13:29 +0000, via Digitalmars-d wrote:
[…]
> You are doing Python a disservice here. Their use of exceptions 
> for control flow statements is an implementation detail, 
> introduced because Python exceptions are fast. (In the C runtime 
> a Python exception is a global variable and functions that return 
> 0;. ) The whole argument stands on its head.

I think you miss my point. The thread appeared to be assuming the use of
exception handling was a boolean, whereas it is a scale. The cost of
raising and handling an exception compared to the cost of a function
call is a critical metric. Thus C++ exception handling is at one scale,
Python at a totally different one, with Java somewhere between. The cost
determines the idioms. Because exceptions are so cheap in Python it can
be used for implementation detail, and is.

I assume D sits with C++ rather than Java, so exception handling is for
termination semantics, not error handling. Certainly not for control
flow as with Python.

Go does have exceptions, there is one and it terminates execution.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150113/5d6c5ef8/attachment.sig>


More information about the Digitalmars-d mailing list