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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:07:08+00:00 2026-06-11T00:07:08+00:00

This is probably a really simple question, but I just can’t find any info

  • 0

This is probably a really simple question, but I just can’t find any info on it.

I work with a system that aggregates a lot of data from various sources and then stores that data in a database. For the most part, the system works fine, but occasionally we get an issue where data can have awkward character encoding (for instance, when the data is in another language, like French) that our system doesn’t like.

The data gets passed to our processing server (we use Gearman), and to ensure that all the info pertaining to source gets passed we json_encode an array with everything we need. My question to you is: if I wrap the json_encode in a try/catch block, will things that cause “PHP Warning: json_encode(): Invalid UTF-8 sequence in argument” messages trigger the catch block to activate?

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-06-11T00:07:10+00:00Added an answer on June 11, 2026 at 12:07 am

    No but you can check it’s return value in a function and throw an exception when something goes wrong. You can also use json_last_error to get details on the error

    Example:

    function my_json_encode($data) {
        if( json_encode($data) === false ) {
            throw new Exception( json_last_error() );
        }
    }
    
    try {
        my_json_encode($data);
    }
    catch(Exception $e ) {
        // do something
    }
    

    I do find it highly annoying that to get the actual error message you have to check a list of constants that is returned from json_last_error(). In the past I’ve used a switch / case statement to make that happen but you could throw different exceptions depending on the error.

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

Sidebar

Related Questions

This is probably something really simple but for some reason I just can't seem
This is probably a really simple question but one I've never quite worked out
This is probably a really dumb question with a simple answer but... I am
This is probably something really simple but I cant see what! Any images I
This is probably going to be a really simple fix... I just can't figure
This is probably a really simple question, and I'm just not getting it. I'd
Probably a really simple question to answer but I can't for the life of
This is probably quite a simple question, but I can't remember how to do
I know this is probably a really simple question but I'm having a brain
I just started working with assembly so this is probably a really simple question,

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.