Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: What technical benfits perl offers over python + few more questions.

by ikegami (Patriarch)
on Nov 15, 2021 at 15:50 UTC ( [id://11138837]=note: print w/replies, xml ) Need Help??


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:

  • Perl operators don't throw exceptions, while the corresponding IO libraries in other languages might.

  • Perl exceptions don't automatically come with a stack trace, whereas it's common elsewhere. It's definitely possible to get stack trace from exceptions in Perl, through. See Carp::Always.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138837]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found