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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:12:18+00:00 2026-05-14T19:12:18+00:00

i wanna catch all exceptions thrown in a script and then check if they

  • 0

i wanna catch all exceptions thrown in a script and then check if they have a error code 23000.

if they don’t i want to rethrow the exception.

here is my code:

function myException($exception) {
    /*** If it is a Doctrine Connection Mysql Duplication Exception ***/
    if(get_class($exception) === 'Doctrine_Connection_Mysql_Exception' && $exception->getCode() === 23000) {
         echo "Duplicate entry";
    } else {
         throw $exception;
    }
}

set_exception_handler('myException');

$contact = new Contact();
$contact->email = 'peter';
$contact->save();

but i get this error message and i dont know what it means:

Fatal error: Exception thrown without a stack frame in Unknown on line 0

i want to be able to rethrow the original error message if it has not the error code 23000.

even when i deleted the check errorcode i still get the same message:

function myException($exception) {
    throw $exception;
}

set_exception_handler('myException');

$contact = new Contact();
$contact->email = 'peter';
$contact->save();

how could i solve this?

thanks

  • 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-14T19:12:18+00:00Added an answer on May 14, 2026 at 7:12 pm

    Don’t use the exception handler for this.

    The exception handler is only the “last resort” to handle uncaught exceptions.

    You can’t throw a new exception within it – it would lead to an infinite loop.

    The regular way to handle exceptions is using a try... catch {} block:

    try
     {
      $contact->save();
     }
    catch (Exception $exception)
     {
      if(get_class($exception) === 'Doctrine_Connection_Mysql_Exception' 
         && $exception->getCode() === 23000) {
             echo "Duplicate entry";
        } else {
             throw $exception; // throw it on if it's not a doctrine exception
                               // (if that's what you want)
        }
    
     }
    

    I know this looks way more messy than the way you do it. That’s why I’m not really fond of exceptions.

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

Sidebar

Related Questions

I wanna get the Timedate value from another page using request.querystring and then use
I wanna place two child un-ordered lists side by side. They are having Class
I have a table with N rows, and I wanna select N-1 rows. Suggestions
I wanna do something like this: int main() { try { runApp(); } catch(std::exception
I have a WCF service which all operations return type is OperationStatus: [DataContract] public
I wanna catch Php classes from a file: class a { function test() {
Wanna write a RegEx to validate a driving license. if it doesn't start with
I wanna stop the reading of my text input file when the word synonyms
I wanna add server controls by using javascript. The main purpose of why I
I wanna do something like the safari app when fill a form, so when

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.