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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:15:39+00:00 2026-05-26T05:15:39+00:00

I have a try-catch block that iterates over a set of records like this:

  • 0

I have a try-catch block that iterates over a set of records like this:

try {
  foreach ( $json['location'] as $records ) {
    $location = DnaExtractionTable::getInstance()->find($records['id']);
    $location->setName($records['name']);
    $location->setLatitude($records['latitude']);
    $location->setLongitude($records['longitude']);
    $location->setCountryId($records['country_id']);
    $location->setRegionId($records['region_id']);
    $location->setIslandId($records['island_id']);
    $location->setRemarks($records['remarks']);
    $location->save();
  }
}
catch (Exception $e) {
  ...
}

I can catch every exception that is thrown and continue without problems. But I am also trying to “catch” the errors, e.g. when a index does not exist in the $records array.

Is it possible to do that? How I can do it? I’ve been playing with set_X_handler functions without success.

UPDATE 1:

Following advices from comments and answers, I decided to implement a global error function:

function exceptions_error_handler($severity, $message, $filename, $lineno) {
  if (error_reporting() == 0) {
    return;
  }
  if (error_reporting() & $severity) {
    throw new ErrorException($message, 0, $severity, $filename, $lineno);
  }
}
set_error_handler('exceptions_error_handler');

But even if I try to force an error the code does not execute. Since I am developing with Symfony, is there a place to declare that function? Could be Symfony disabling or affecting the set_error_handler function?

UPDATE 2:

Symfony is definitely messing around with my error and exception handlers.

Turning on the debugging mode seemed to activate a Symfony custom exception handler that overrides error reporting.

Turning off the debugging mode seemed to bypass certain exceptions although my try-catch block is configured to catch general Exception objects. Really strange behavior.

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-26T05:15:40+00:00Added an answer on May 26, 2026 at 5:15 am

    See the answer to Handling errors as exceptions. Best methods? for a way to throw exceptions when an error is raised.

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

Sidebar

Related Questions

I have a try catch and finally block like this. Client client = new
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like
I have a try - catch block that I wish to break like a
I have a try/catch block that throws an exception and I would like to
I have code like this try { header(Location: http://www.google.com\n-abc); } catch (Exception $e) {
I have a little Try Catch block that will tell the user more detailed
I have a stored procedure that performs an update with a try catch block.
I have the following try catch block that executes on a button click. try
I have a do...while loop and a try...catch block that wraps around database centric
I have several database access methods that are wrapped in a try/catch block: function

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.