lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wednesday 10 August 2005 23:29, Glenn Maynard wrote:
[...]
> (setjmp is evil, but so are C++ exceptions, at least in practice: they
> bloat binaries far more than their value, in my opinion.  I tend to
> stick to old-fashioned error returns.)

I have a C++ program, Spey, which is an SMTP proxy implementing greylisting. I 
wrote it specifically to be reliable, scalable, and secure. (It's very neat 
and uses coroutines. <PLUG> http://spey.sf.net </PLUG>)

It uses exceptions extensively in order to communicate error states. Yes, 
they're not cheap in terms of code size, but used properly they can *vastly* 
simplify your logic flow. Another thing I was doing was never dynamically 
allocating anything if I could possibly help it; I think I use the new 
operator once in the entire program. (Although I do use STL containers quite 
a lot.) Since C++ exceptions call destructors, this means that all my memory 
allocation problems basically go away.

Hauling the subject bodily back on topic, one of the few issues I have with 
Lua is that there's no standard for exceptions. There is no consistent 'out 
of memory' exception; some parts throw a string, some a number, some return 
an error code, some return an error string, etc. The other standard failure 
cases are all quite similar.

I do feel strongly that the use of exceptions can very much improve a program, 
and in keeping with the Lua philosophy, it would be a good idea to provide a 
standardised framework that application and library writers can use. Part of 
this framework should, I think, involve standard exception *names*. 
Otherwise, there's no way of knowing if you've caught a standard exception or 
not.

-- 
"Curses! Foiled by the chilled dairy treats of righteousness!" --- Earthworm 
Jim (evil)

Attachment: pgpcLLHI4W4ib.pgp
Description: PGP signature