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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:49:12+00:00 2026-05-14T08:49:12+00:00

We have a REST API that works great. We’re refactoring and deciding how to

  • 0

We have a REST API that works great. We’re refactoring and deciding how to internally handle errors by the users of our API.

For example the user needs to specify the “movie” url parameter which should take the value of “1984”, “Crash”, or “Avatar”. First we check to see if it has a valid value.

What would be the best approach if the movie parameter is invalid?

  • return null from one of the internal methods and check for the null in the main API call method
  • throw an exception from the internal method and catch exceptions in the main API method

I think it would make our code more readable and elegant to use exceptions. However, we’re reluctant because we’d be potentially throwing many exceptions because of user API input errors, our code could be perfect. This doesn’t seem to be the proper use of exceptions. If there are heavy performance penalties with exceptions, which would make sense with stack traces needing to be collected, etc., then we’re unnecessarily spending resources when all we need to do is tell the user the parameter is wrong.

These are REST API methods, so we’re not propogating the exceptions to the users of the API, nor would we want to even if possible.

So what’s the best practice here? Use ugly nulls or use java’s exception mechanism?

  • 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-14T08:49:13+00:00Added an answer on May 14, 2026 at 8:49 am

    Neither.

    The key is that passing a bad parameter isn’t that exceptional a condition. Exceptions are thrown for exceptional circumstances. (That’s the reason to not use them here, not the performance.)

    You should be using something like Spring’s DataValidation API for binding parameters that are passed in.

    A client of a REST API should not be receiving null or exceptions. They should get an error message that gives them an idea of what’s going on without exposing those details. “Sorry, we couldn’t find that movie” or null? Go with the first, hands down.

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

Sidebar

Related Questions

I have a symfony project. There is a website and a rest API that
I have a portion of my site that has a lightweight xml/json REST API.
We have a REST API which clients routinely POST and PUT data to. When
We are trying to implement a REST API for an application we have now.
I have a REST data service where I want to allow the users to
I have an application with a REST style interface that takes XML documents via
I have a web service class that the rest of the framework depends on
I have a REST API written in PHP located on Apache server. It takes
I have a REST API where I would like to cache the JSON response
I'm writing a app that exposes a REST API. Some of the query parameters

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.