lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> And IMHO here's the point: you have to consider every possible exception
> the same as the error return codes of ie a C function.  

Agreed.

> But the exceptions
> make you feel save (a la: will be handled by upper levels anyway) and you
> become lazy.  

This is no worse of a problem than already exists with returning error
codes.  However exceptions provide a valuable feature over and above
returning error codes.  Several, in fact, but I only want to address one
particular one right now.

Exceptions decouple error detection from error handling.

It's that simple.  The routines that can typically tell that an error has
occured -- opening a file, for example -- usually have no idea what to do
about it.  They lack the application's context to make any kind of
intelligent decision.  They can only report that the error has happened. 
Conversely, the routines that have sufficient application context to make
intelligent decisions on how to handle an error, have no means of detecting
that an error has happened.

Even worse, there are often several layers of function calls between the
routine that can identify and report an error and the routine that can do
something about it.  And if any single one of these neglects to pass the
error up the chain, the high level function can do absolutely nothing about
the error -- indeed can't do anything to even tell that an error has
happened.

Exceptions cut through all that.

The routines that can tell an error occured only have to signal the error. 
They need to know nothing at all about the context of the error.  The
routines that can handle the error will always know when it happens without
relying upon any of the intermediate code to pass things along.  Further,
properly implemented, exceptions CANNOT BE IGNORED.  (This alone makes them
incredibly valuable when compared to return codes.)  If you do the Wrong
Thing (ignore your error handling) you will find it out in a manner that is
unequivocal when you have exceptions in the loop.  There won't be any
broken open() calls where you blithely use an invalid handle and write your
data into a bit bucket.  Your program will stop working.  Violently.  You
will see this.  And you will handle that error condition.

I'm not sure that exceptions could be added cleanly to Lua (although I'm
now toying with some exception-handling function concepts -- Lua may just
be powerful enough to pull this off).  But if they get added to Lua without
breaking its elegance, you'll see me dancing a jig of joy over here.

-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBOvXuw7TM3QkE7U/oEQJrBwCfX2XximDPT9iEPlSAC+P2NZJ5OnAAoIId
0C0zqBdwfUmPtZ4nfqaRRFYY
=56Yk
-----END PGP SIGNATURE-----