Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by Anonymous Monk
on Nov 14, 2021 at 18:49 UTC ( [id://11138812]=note: print w/replies, xml ) Need Help??


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

Hi Hippo

Here is one of the links that talks about exceptions not being part of Perl. My bad again, I got mixed up with errors and exceptions, and if you berate me for that I would totally understand- https://www.oreilly.com/library/view/mastering-perl/9780596527242/ch12.html

Given below is paragraph from the chapter -

Exceptions Perl doesn’t have exceptions. Let’s just get that clear right now. Lik +e some other things Perl doesn’t really have, people have figured out + how to fake them. If you’re used to languages, such as Java or Pytho +n, set the bar much lower so you aren’t too disappointed. In those ot +her languages, exceptions are part of the fundamental design, and tha +t’s how I’m supposed to deal with all errors. Exceptions aren’t part +of Perl’s design, and it’s not how Perl programmers tend to deal with + errors.

Unfortunately I could not find other links. I was just going from one article to another and that is how I stumbled across the said articles.

Note:- I am not hear to badmouth about Perl. Just really badly wanting to get some clarity (which the ensuing answers have provided in truckloads).

  • Comment on Re^2: What technical benfits perl offers over python + few more questions.
  • Download Code

Replies are listed 'Best First'.
Re^3: What technical benfits perl offers over python + few more questions. (Try Catch)
by eyepopslikeamosquito (Archbishop) on Nov 15, 2021 at 03:40 UTC
Re^3: What technical benfits perl offers over python + few more questions.
by hippo (Bishop) on Nov 14, 2021 at 21:39 UTC

    Exceptions are not an explicit part of the Perl language, but fatal errors are and can serve a similar purpose. However, as with many other topics, exceptions are well catered for on CPAN with almost 4000 results for "exception". If you do want to use exceptions with Perl there are many ways to do so.


    🦛

Re^3: What technical benfits perl offers over python + few more questions.
by ikegami (Patriarch) on Nov 15, 2021 at 15:50 UTC

    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.

      > 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.

        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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (None)
    As of 2024-04-25 00:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found