Subject: Developers of Sympa
List archive
- From: Guillaume Rousse <address@concealed>
- To: address@concealed
- Subject: Re: [sympa-developpers] Sympa and croak
- Date: Fri, 07 Dec 2012 11:21:27 +0100
Le 07/12/2012 11:03, David Verdin a écrit :
Hi guys,croak has the same effect as die: it raises an exception.
I see an alarmingly growing number of croak calls in the Sympa code. I
think I misunderstand what this function does.
As far as I understand it, it simply kills the program after having
issued a last log. However, it looks like Sympa doesn't die any time
corak is called, so I think I don't fully understand what exactly is the
effect of croak.
The only difference is in the context reported:
- with die(), the file and line number is the one from the called code
- with croak(), the file and line number is the one from the caller code
See the attached test case for an example.
That usually refered as 'dying from the caller perspective', and it's considered a best practice for general-purpose modules, meaning code intended to be used by other people. Indeed, if there is an exception in IO::Socket::SSL, for instance, you're not really interested in debugging this module, but rather where did your own code call it.
For Sympa private modules, intended to be used in sympa code only, I don't think we have any interest in croak vs die.
In which cases, in our code, will croak actually kill the process?If the exception is not caught, the process will get killed. So any code susceptible of raising an exception should be enclosed in an eval block. Think of a try/catch block in many other languages.
Because we must not kill our processes on errors. Errors will happen all
the time. We must warn users, send mail, but never kill the processes,
except if they can't access vital ressources, such as database.
eval {
run_dangerous_code;
};
if ($EVAL_ERROR) {
something wrong happened...
}
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31
Attachment:
test.pl
Description: Perl program
Attachment:
smime.p7s
Description: Signature cryptographique S/MIME
-
[sympa-developpers] Sympa and croak,
David Verdin, 12/07/2012
- Re: [sympa-developpers] Sympa and croak, Guillaume Rousse, 12/07/2012
-
Re: [sympa-developpers] Sympa and croak,
IKEDA Soji, 12/07/2012
-
Re: [sympa-developpers] Sympa and croak,
Guillaume Rousse, 12/07/2012
- Re: [sympa-developpers] Sympa and croak, David Verdin, 12/11/2012
-
Re: [sympa-developpers] Sympa and croak,
Guillaume Rousse, 12/07/2012
Archive powered by MHonArc 2.6.19+.