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

  • SEARCH
  • Home
  • 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 7031001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:44:43+00:00 2026-05-28T00:44:43+00:00

I admit I do not use Exceptions a whole lot and they are at

  • 0

I admit I do not use Exceptions a whole lot and they are at time hard for me to grasp 100% in PHP, this could be partially because PHP does not have the best error => Exceptions support but none the less I do not know much about them.

Take for example this code below, it has 4 different Classes defined that do nothing but extend a base Exception class. I am just curious why one would not just call an Exception and why they have all these separate classes.

I assume there is a good reason?

class OptimizeImageException extends Exception {};

class FileNotFoundException extends OptimizeImageException {};

class FileNotImageException extends OptimizeImageException {};

class ModuleNotFoundException extends OptimizeImageException {};
  • 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-28T00:44:44+00:00Added an answer on May 28, 2026 at 12:44 am

    By having multiple Exception classes, you can pick out which one you’re interested in when catching them.

    <?php                                                                       
    class OptimizeImageException extends Exception {};
    
    class FileNotFoundException extends OptimizeImageException {};
    
    class FileNotImageException extends OptimizeImageException {};
    
    class ModuleNotFoundException extends OptimizeImageException {};
    
    try {
      throw new FileNotImageException();
    } catch (FileNotFoundException $x) {
      echo "NOT FOUND!";
      // do something about it
    } catch (FileNotImageException $x) {
      echo "NOT IMAGE!";
      // do something about it
    } catch (Exception $x) {
      echo "UNKNOWN EXCEPTION!";
      // do something else about it
    }
    

    This is a trivial example, but say you have a function loadImage() which is supposed to load an image. If the function fails, you can handle different failure scenarios differently. If you always throw a basic Exception, you only know something went wrong. You don’t know what went wrong, so you can’t have different recovery responses based on different scenarios, not without using another mechanism (which then makes exceptions rather weak).

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

Sidebar

Related Questions

I admit, I'm new at this whole Android stuff. I am trying to make
I've notice django admin UI does not allow use name with characters that are
I'll admit I'm not very adept at key verification. What I have is a
After looking around (for not terribly long I have to admit) I wonder if
Before I begin I'll freely admit it's something in my code but it's not
Background I admit, this question stems from an ultimate lack of deep understanding of
OK so I admit right off the top that this is a bit screwy
OK, I admit it this code will just look weird to you, and that's
Long time stackoverflow reader, first time poster. Forgive me if I'm not asking a
GAE 1.5.5 looks to have some excellent, long-waited for features. However, they're not working

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.