On Thu, Aug 17, 2000 at 01:19:22PM -0500, Jarkko Hietaniemi wrote:
> I recently suggested in p5p that for many system calls it could be
> checked in *consta...darn, *compile* time whether they are used in
> void contect, and _abort_.  "No, I'm not going to let you get away
> with doing a chdir() and not caring."  For some other system/library
> calls, like print() and close(), this may too strict, but for those a
> run-time check could be made: if they either return an error (-1, or
> somesuch), or the errno flips (before the call errno would explicitly
> reset to zero), we would die.  Or warn.  Whatever.  As long as there
> would no way to completely ignore errors.  Though I suggested this in
> a p5p thread, this is definitely more like p6 fodder.

This is, of course, one of the main reasons that exceptions exist --
you can ignore exceptions, but you have to explicitly ask for it.

This is one of the nice things about Python, in my opinion.  Every
error is an exception, so you can feel free to completely ignore
errors when writing a quick one-off, safe in the knowledge that if
anything gets wrong, you'll be told.

Java combines what you're talking about (enforced error checking)
with exceptions; since every method that throws an exception must
declare the exception thrown, the compiler can (and does) enforce
that the caller explicitly deal with any exceptions that might
happen.  I find this quite nice under some situations, but I think
it's a bit more bondage-and-discipline than suits Perl.

Hmm.  It just occurred to me that you could combine your idea with
exceptions quite nicely: All core functions throw exceptions on
error, but only when called in a void context.  (As well as, perhaps,
when a given pragma is in effect.)  This way, old code which correctly
checks errors will run without modification.  Old code which
incorrectly ignores errors will get error checking.  (And old code
which correctly ignores errors breaks, which is probably enough of
a problem to torpedo the whole idea.  Alas.)

  open(FD, "foo") or die;   # Scalar context, no exception thrown.
  open(FD, "foo");          # Void context, exception thrown on error.

                      - Damien

Reply via email to