Subject: | please do not use $! as default error message |
Hello,
I am currently annoyed by Exception::Class assuming that $! is the
default cause of any exception.
Scenario:
- make a system call that fails, e.g., open a non-existing file. $! is
set.
- decide that this failure is not important and go on.
- later, for something completely different, throw an exception, through
Exception::Class, but without specifying an 'error' or 'message'
argument.
- the as_string() method will mention the 'file not found' error that
happened earlier, although it is not related to this exception in any
way.
perlvar says that $! is only set when a system call fails. It is not
reset when another system call later succeeds. It is not reset when the
error that caused $! to be set is handled.
I would suggest to not make $! a default value, and let the calling code
decide whether $! should be knowned to the exception or not. Or at
least, to keep backward compatibility, provide a subclass for exceptions
that have nothing to do with system calls.
TIA and best Regards.