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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:43:27+00:00 2026-05-30T19:43:27+00:00

Any errors that are thrown on the server side (PHP) is captured in a

  • 0

Any errors that are thrown on the server side (PHP) is captured in a hash and sent back to the client side (javascript) via AJAX. In this way, the JSON of errors is actually delivered to the AJAX success event.

...
catch ($e) {
    echo ( array("error" => $e->getMessage()) );
}

I essentially check if data[“error”] is undefined and if not, I want to throw a new error that would theoretically be caught in my try/catch block encapsulating the entire AJAX.

...
success : function(data) {
    if (typeof(data["error"]) != "undefined") {
        throw new Error(data["error"]);
    }

    handleGoodData(data);
}

It keeps telling me that the error is uncaught (via Chrome console). I have checked and data[“error”] returns a string if it is defined.

Even in the simplest form, simply throwing a new error in the success event doesn’t seem to work either:

success : function(data) {
    throw new Error("error message!");
}
  • 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-30T19:43:29+00:00Added an answer on May 30, 2026 at 7:43 pm

    you have to encapsulate your success and error functions actually in try catch blocks to be able to catch errors within them. One solution is to create a layer between $.ajax calls so that it goes through your own function first. For example:

    myajax: function(settings) {
    
                // override provided success callback with try catch
                if (settings.success){
                    var successFunc = settings.success;
                    settings.success = function(){
                        try{
                            successFunc.call(arguments);
                        }
                        catch(error){
                            console.log("An unhandled error occurred in ajax success callback: " + error);
                        }
                    };
                }
    
                // override provided error callback with try catch
                if (settings.error) {
                    var errorFunc = settings.error;
                    settings.error = function() {
                        try{
                            errorFunc.call(arguments);
                        }
                        catch(error){
                            console.log("An unhandled error occurred in ajax error callback: " + error);
                        } 
                    };
                }
                // else create our own basic error callback
                else {
                    settings.error = function(jqXHR, textStatus, errorThrown) {
                        console.log("An unhandled error occurred during an AJAX call: " + errorThrown);
                    };
                }
    
    
                $.ajax(settings);
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that the MySQL errors are split into client and server types. Has
Are there any cases when it's a good idea to throw errors that can
Because I am a newbie I am trying to log out any errors that
I'm trying to make a web app that will read in a server-side CSV
I want to make sure that if any error occurs during the database processing
First of all, it needs to create some codes that handle any error in
I want to number any JSF error messages (e.g. validation, conversion messages) that appears
I'm not getting any errors as such just a minor performance issue. EXPLAIN SELECT
So: @fopen($file); Ignores any errors and continues fopen($file) or die(Unable to retrieve file); Ignores
I did not make any changes on the code. I dont receive any errors

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.