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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:00:18+00:00 2026-05-13T10:00:18+00:00

I am pretty new to using object/classes in PHP and I am curious about

  • 0

I am pretty new to using object/classes in PHP and I am curious about EXCEPTIONS, TRY, and CATCH

In the example below I have all 3 shown in use. Obviously an exception is some sort of way of triggering an error but I do not understand why? In the code below I could easily show some sort of error or something without the exception part there?

Below that example is an example using try and catch. It appears to me to be the same as using if/else. I may be wrong, this is just the way I see them without knowing anything, I realize you can code anything in PHP without using these so what is the reason, is there any benefit over using this stuff vs the traditional ways?

<?PHP
// sample of using an exception
if($something === $something_else){
    //do stuff
}else if($something === $something_else_again){
    //do stuff
}else{
    throw new Exception('Something went wrong!');
}

try and catch

//and try and catch
try{
    $thumb = PhpThumbFactory::create('/path/to/image.jpg');
}
catch (Exception $e){
    // handle error here however you'd like
}
?>
  • 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-13T10:00:19+00:00Added an answer on May 13, 2026 at 10:00 am

    To make things short, an exception is a “special condition that change the normal flow of program execution” (quoting wikipedia)

    You might be interested by (at least) those couple of articles :

    • Exception handling – wikipedia
    • Exceptional PHP: Introduction to Exceptions
    • Exceptional PHP: Extending The Base Exception Class
    • Exceptional PHP: Nesting Exceptions In PHP

    They should give you some interesting elements — especially the second one, for “what is an exception in php”

    One of the advantages (which is part of the basic idea) is :

    • you have the “normal” code in the try block
    • and the biggest part of the “dealing with problems” code is in the catch block
    • which means less “dealing with problems” code in the middle of the “normal” code
    • and also allows you to regroup “dealing with problems” portions of code
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you tried facebook developer articles? May 14, 2026 at 5:16 am
  • Editorial Team
    Editorial Team added an answer You could wrap the controls in a Layout, e.g. a… May 14, 2026 at 5:16 am
  • Editorial Team
    Editorial Team added an answer It's ok - Garbage Collection will pick it up for… May 14, 2026 at 5:16 am

Related Questions

Let me start by saying I'm pretty new to using interfaces. I'm writing a
I am new to Ruby and currently trying a few examples from the Ruby
During my apprenticeship, I have used NHibernate for some smaller projects which I mostly
I know this should be a pretty elementary issue to fix, but 1) I'm
I am pretty new to the ldap based directory service programming using .net framework;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.