in reply to Re^2: What technical benfits perl offers over python + few more questions.
in thread What technical benfits perl offers over python + few more questions.

Perl has exceptions, and that's nothing new. Exceptions are thrown using die, and caught using eval BLOCK.

Differences:

Replies are listed 'Best First'.
Re^4: What technical benfits perl offers over python + few more questions.
by LanX (Saint) on Nov 15, 2021 at 16:46 UTC
    > Perl operators don't throw exceptions, while the corresponding IO libraries in other languages might.

    could you please elaborate what you mean?

    DB<37> eval { 1/0 } or print "<$@>" <Illegal division by zero at (eval 46)[c:/Strawberry/perl/lib/perl5db. +pl:738] line 2. > DB<38>

    edit

    Probably you are talking about the kind of non-error "message" exceptions , e.g. thrown by iterators like in Python???

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      I think the distinction being made is maybe that in (say) Java trying to print on a closed filehandle object would throw an IOException which your code would be required to handle, whereas perl  -E 'close(STDOUT);say qq{FOOP}' will run (producing no output but also not printing any sort of error (although you could check the return from say and print $!)).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Of course if you "use warnings;", you will see the "print() on closed filehandle STDOUT" warning.

      ok, so you found an exception. Well, kinda. There's no IO library function that corresponds to division.

      Anyway, the point stands: Where other languages might use exception, Perl primarily returns false on error.

      Update: Clearer wording

        So you were only talking about IO and meant the lack of default to autodie?

        Wasn't obvious to me.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery