lua-users home
lua-l archive

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


Hi,

Is there a simple way to handle exceptions in lua ... like in others
languages ?
For example with Ada, I just do :

	begin
		some code
		raise first_error
	exception
		when first_error =>
			some code
	end

In lua, I have to do like this :

	local b, err = pcall(function()
		some code
	end)
	if not b then
		if err == "first error" then
			some code
		else	error(err)
		end
	end

Typing this code, I realize that it is not so bad ... But I still
don't like declaring local variables to handle my exceptions, and
sometimes the error string is not so easy to verify (io.open for
example. the error message contains the file name).
And also you always have to check the documentation to kwow if you have
to do an assert() on the function or not ...
So, is there a better solution ?

Thanks

Mildred
-- 
Mildred
Website	<http://louve.dyndns.org> ou <http://mildred632.free.fr>
GnuPG	<http://mildred632.free.fr/gpg_key> ou hkp://pgp.mit.edu
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 <9A7D_2E2B> (ID)
Ce courrier E-mail doit être considéré comme une correspondance privée.