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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:59:30+00:00 2026-05-18T23:59:30+00:00

Sup guys. I’m using ajax to load in a bunch of data with php.

  • 0

Sup guys. I’m using ajax to load in a bunch of data with php. Sometimes exceptions go uncaught. This generates some error messages which javascript cannot parse (because it’s expecting json). This crashes the page, that’s not cool. So I’m building a custom exception handler. Basically it should just json_encode the Exception object. But json only works on objects of type stdClass. So here’s the actual question:

How do you cast an exception object to stdClass, so that I can json_encode it? I’ve tried all the naive stuff I could think of, like

(stdClass) $ex and (Object) ((Array) $ex)

And yeah, I know that exceptions shouldn’t be uncaught to begin with, but it’s more like a development feature. It makes debugging less painful 😉

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-18T23:59:30+00:00Added an answer on May 18, 2026 at 11:59 pm
    1. PHP doesn’t support object casting.
    2. Using exceptions handler in this case is an horrible idea, especially when all you have to do is:

      try {
          // Current code here, including other try-catch blocks
      } catch (Exception $e) {
          // handle uncaught exception
      }
      
    3. When error occurs you should setup response correctly. Set Response Code to 500 (Internal Server Error) so JavaScript could easly handle that.

    4. Exception object provides only getMessage() and getCode() methods that could be usefull, so response body could be generated like so:

      $responseBody = json_encode(array(
        'message' => $e->getMessage(),
        'code'    => $e->getCode()
      ));
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sup guys. I'm loading data into a table using ajax and jquery. This can
What's up guys! I gonna need some help! Inside of this code return ControllTheDog(D,
Sup Guys, I Have a Function on my frmMain Class wich will update my
I have some .dat and .idx files and one .sup file in a directory
Sup fellas, I am using the script that a fellow stack overflow user posted
Namely, how does the following code: var sup = new Array(5); sup[0] = 'z3ero';
I have the following text: txtAddressSup.Text I want the Sup to be replaced by
If I have a <sup> element in a multi-line paragraph, the line with the
Possible Duplicate: relative font-size of <sub> or <sup> and their descendants in IE I'm
What's up with my Footer CSS ? Using the Web Dev toolbar in Firefox

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.