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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:45:17+00:00 2026-06-12T19:45:17+00:00

I have a PHP RESTful API, which returns JSON objects. I have an Android

  • 0

I have a PHP RESTful API, which returns JSON objects.
I have an Android client requesting REST requests from that API

Till now if there was a problem in the server side then the API returned a booleanic response “false”

I want to change the flow of the API, so instead of sending a JSON response containing “false” it will throw and Exception, and I want the android side to catch the exception.

So basically, i want something like the following Android code:

try {
    php_api.getUsers();
} catch (Exception ex) {
    // TODO
}

Can it be done?
Will any PHP exception be caught in this way?

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

    I haven’t worked with Java but I don’t think that you can do that.
    When PHP throws an exception, it will still produce an output of some sort, depending on how you set up exception handling.
    It could show the exception message with a stack trace or something similar.
    But on the client (your Java app) side, this is nothing more than text.

    However, a rest response should always have headers that you can check. Take a look at this: http://blog.zenika.com/index.php?post/2011/05/18/Error-handling-with-REST

    By following what is written there, your Java-to-PHP api would always read the response headers before returning the content. If a 500 or 400 showed up, you’d throw a java exception from the api which you could catch in the code that uses it.

    If your PHP side is not sending the headers you want, you can always override PHP’s error/exception handling to produce custom output (including headers).

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

Sidebar

Related Questions

I have a custom implementation of a RESTful API for a PHP application that
I have created a RESTful PHP web service using Lithium which contains comments, each
I am creating a RESTful API in PHP, and have encountered a problem. When
I am building a RESTful web service in PHP that accepts JSON as its
I am creating a php restful API and currently I have the database connection
I am developing RESTful with php. Currently I have started coding with MVC design
I have php code that puts some values into an Array as follows: $hunter=addslashes($MessageArray[1]);
I have php script that creates a temporary watermark image for users that are
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
For one specific client I have to use PHP. This and this question were

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.