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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:53:28+00:00 2026-06-01T03:53:28+00:00

This might be a n00bish question, but whatever. Is okay to use exceptions for

  • 0

This might be a n00bish question, but whatever. Is okay to use exceptions for form validation? Let’s say I have a form which asks users for their name and email, is right to do the following?

try {
    if (empty($_POST["name"])) {
        throw new UserRegistrationException("Your name cannot be empty.");
    }

    if (filter_var($_POST["email"])) {
        throw new UserRegistrationException("Invalid email");
    }

    // Save new user into database
} catch (UserRegistrationException $e) {
    // Show errors on screen
}

Also -if this is in fact the correct way to do it- if the user submits both an empty name and an invalid email, would both of the exceptions execute or only the one that appears first (the name one in this case)?

I’m using PHP by the 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-01T03:53:29+00:00Added an answer on June 1, 2026 at 3:53 am

    I personally like to use exceptions for anything that should stop or alter program flow. In other words, if validation of a particular field changes how data is processed, or requires the process to be repeated, then I always use exception for error handling.

    If it’s trivial, or I’m simply compiling a list of error messages, then I do not trigger exceptions.

    To answer questions, two exceptions cannot be thrown at the same time. The first throw statement that is reached will be thrown. That’s not to say that sometimes it doesn’t make sense to rethrow as another type of exception.

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

Sidebar

Related Questions

This might be a trivial question, but I have not found anything about it,
This might be a stupid question but I have spent 2 hours looking for
This might be a pretty simple question but I'm a Crystal Reports newbie...I have
This might be basic question but how do I create a list of lists
This might be a simple question, but i can't seem to grasp it. I
This might seam like a strange question but.... public string MyProperty { get {
This might be a simple question but I'm just picking this up so please
This might be a little bit odd question, but Im trying to figure out
This might be a very basic question, but I'm getting a bit confused. I'm
This might be an odd question, but how does one nicely loop over ALL

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.