Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3801840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:06:48+00:00 2026-05-19T14:06:48+00:00

I have it drilled into my head that (at least in PHP) it is

  • 0

I have it drilled into my head that (at least in PHP) it is badbadmojo to use try... catch blocks for flow control. What I’ve learned is to use them only to handle unexpected errors, not determine the logic flow of the program, because catch blocks are expensive.

Now that I’m learning python, I see a lot of exceptions everywhere and the EAFP principle. Does this mean that python is more efficient at handling exceptions, so I don’t need to be as worried about them for flow control, or does the principle still stand? If not, is PHP the exception from the norm (as compared to other languages), or is Python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:06:49+00:00Added an answer on May 19, 2026 at 2:06 pm

    Historically, in languages like C++, exceptions have been very slow compared to other forms of flow control in the same language.

    In C++, there are two things at work:

    • Throwing an exception is very complex. The stack needs to be unwound, and doing so in native code is much harder than in a high-level VM-based language.
    • Regular, direct flow control is extremely fast. It’s native code; a branch is a couple instructions, where an exception rolling back the stack invokes a complex algorithm (looking up stack data in a large, possibly compressed table, and so on).

    This disparity in performance led to the general wisdom behind exceptions: only do it for unusual things, so it’s only used where it’s most beneficial and not where it’ll hurt performance.

    This does not apply to high-level languages. This is also for two reasons:

    • Rolling back the stack is much, much simpler. The stack is very easy to examine; you don’t need magic tables to know how far to roll back the stack and what objects are constructed at any given time.
    • Regular program flow is inherently slower. In a VM-based language, everything simply takes more work to begin with.

    Exceptions still aren’t free, but the disparity is no longer something to worry so much about. This means the general wisdom formed in C++ is misapplied here. Exceptions are regularly used in normal program flow.

    In fact, they’re built into language, in constructs you use all the time. Every time you use an iterator–every for x in xrange(1000), a StopIteration exception is used to end the loop.

    Choose exceptions or linear flow control in Python based on which makes more sense. Don’t choose based on performance, unless you’re actually in an inner loop where performance matters; in that case, as always, profile and find out if it actually matters.

    (I can’t speak for PHP.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table being drilled out with PHP in a recorders. I am
I have a table using a table sorter plugin that is getting drilled out
Have an app that can use tts to read text messages. It can also
When I try to drill down into a cube in our client application, I
I'm working from VS10 and have a master page that loads jQuery via: <script
Have a look at one of my websites: moskah.com The problem is that it
Have a problem that seems easy on paper but i'm having a big problem
I have been recently drilled in a couple of interviews about Hashtables and when
This is a head scratcher. I have a form with a number of custom
Have some dates in my local Oracle 11g database that are in this format:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.