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 4013980
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:26:21+00:00 2026-05-20T09:26:21+00:00

Ok, this might be a very noob question, but I find that PHP Documentation

  • 0

Ok, this might be a very noob question, but I find that PHP Documentation on that and several Internet Searches hasn’t give me any idea about that.

When should I use try-catch blocks to improve my application?

I read someone saying that we should use try-catch blocks only to prevent fatal errors.
I read someone else saying that we should use it only on unexpected errors (wait what? unexpected? if they are unexpected errors how could I prevent them with try-catch? should I put all my application code inside a try block?).
Others simply say that try-catch blocks should be used everywhere because they can be also extended (extending the Exception class).
Finally someone says that PHP try-catch block are totally useless because they are very bad implemented. (On this I found a nice SO question about performance).

It seems to me that this topic is very strange and confused. Could someone lights me up?

  • 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-20T09:26:22+00:00Added an answer on May 20, 2026 at 9:26 am

    It seems to me that this topic is very strange and confused. Could someone lights me up?

    Definitely. I’m not a PHP user, but I might have a little insight after having worked with try/catch in ActionScript, Java, and JavaScript. Bear in mind though, that different languages and platforms encourage different uses for try/catch. That said…

    The only times I’d recommend using try/catch is if you’re using a native language function that

    1. Can throw an error/exception
    2. Does not give you any tools to detect whether you’re about to do something stupid that would cause that error/exception. eg: In ActionScript, closing a loader that is not open will result in an error but the loader doesn’t have an isOpen property to check so you’re forced to wrap it in try/catch to silence an otherwise totally meaningless error.
    3. The error/exception really is meaningless.

    Let’s take the examples you list and see how they square with that list.

    I read someone saying that we should use try-catch blocks only to prevent fatal errors.

    In the case of AS’s loader.close() function, this is good advice. That’s a fatal error, and all from an otherwise trivial misstep. On the other hand, virtually ALL errors in AS will bring your application to a halt. Would you then wrap them all in try/catch? Absolutely not! A “fatal error” is fatal for a reason. It means something terribly wrong has happened and for the application to continue on in a potentially “undefined” state is foolhardy. It’s better to know an error happened and then fix it rather than just let it go.

    I read someone else saying that we should use it only on unexpected errors

    That’s even worse. Those are presicely the errors you DON’T want to silence, because silencing them means that you’re never going to find them. Maybe you’re not swallowing them, though… maybe you’re logging them. But why would you try/catch/log/continue as though nothing happened, allowing the program to run in a potentially dangerous and unexpected condition? Just let the error kick you in the teeth and then fix it. There’s little more frustrating than trying to debug something that’s wrong in a program that someone else wrote because they wrapped everything in a try/catch block and then neglected to log.

    Others simply say that try-catch blocks should be used everywhere because they can be also extended (extending the Exception class).

    There’s potential merit to this if you’re the one doing the throwing, and you’re trying to alert yourself to an exceptional situation in your program… but why try/catch your own thrown error? Let it kick you in the teeth, then fix it so that you don’t need to throw the error anymore.

    Finally someone says that PHP try-catch block are totally useless because they are very bad implemented. (On this i find a nice SO question about performance).

    Maybe so. I can’t answer this one though.

    So… this might be a bit of a religious question, and I’m certain people will disagree with me, but from my particular vantage point those are the lessons I’ve learned over the years about try/catch.

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

Sidebar

Related Questions

This might be a very silly / stupid question, but, my defence is that
This might sound like a noob question but this is the first time I'm
This might be a very basic question, but I am a bit confused about
This might be a very stupid question :P But I found this really interessting:
This might have very obvious solution but I'm afraid I cannot find out how
This might be a very simple question, but I can't get it working. All
This might seem a very stupid question but things are pretty complex for me
This might be a very broad question. But this is what i want. I
I know this might be a very stupid question but I am new to
This might be a very stupid question, but I still dont completely understand and

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.