DCPM: Errors and Exceptions included

Matthew Browning mb at matthewb.org
Tue Nov 11 23:31:31 CST 2003


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

On Tuesday 11 November 2003 21:26, Simon Waters wrote:
> Are there any guidelines or good articles on error handling in Perl?
>
> The current program I'm working on it using "eval"/"die"/"$@" very
> much in the style of exception handling one might do in other
> languages (e.g. Java try/catch).
>

This is apparently not my area of expertise but I will point out the 
existance of Error.pm:

http://search.cpan.org/~uarun/Error-0.15/Error.pm

...which gives you try, catch etc. in a nice interface.  This is my 
solution if I'm experiencing this kind of problem and want to keep 
things tidy.

> I'm reasonably happy with it for this small program, although I get
> the feeling it was only ever intended for very rare error conditions.
> Things like if I pass the error message up, I'm going to want to trim
> the line number, as the end user doesn't really care at what line
> things failed, give me this impression.
>

To trim the line number from a die message stick a newline at the end 
of it:

die "I am dead";   # I am dead at line x
die "I am dead\n"; # I am dead


MB

- -- 
http://matthewb.org/public_key.txt

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/scW5y5o0lRFL2ooRAh5eAKDXxTnOsAyUKDSmrKm77db6Xqp/cgCeKCNR
Y7sMvISoiljHYZpGL3Ci1VA=
=X33c
-----END PGP SIGNATURE-----



More information about the Devoncornwall-pm mailing list