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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:57:48+00:00 2026-05-24T03:57:48+00:00

I am trying to re-architect a web application I developed to use the MVC

  • 0

I am trying to re-architect a web application I developed to use the MVC pattern, but I’m not sure how to handle errors. For example:

class AM_Products extends AM_Object 
{
    public function save( $new_data = array() ) 
    {
        // Validate input

        // Save input
    }
}

If I pass invalid input to save, should I throw an exception like this:

class AM_Products extends AM_Object 
{
    public function save( $new_data = array() ) 
    {
        // Validate input
        if ( ! validate( 'text', $new_data['name'] ) ) {
            throw new Exception( 'Invalid data entered' );
        }

        // Save input
    }
}

Or instead, should I add an extra function and leave it to the view/controller:

if ( $product->save( $data )->has_error() ) {
    $error = $product->get_error();
}

echo '<p>' . $error . '</p>';
  • 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-24T03:57:49+00:00Added an answer on May 24, 2026 at 3:57 am

    Don’t throw an exception. Exceptions are for exceptional situations – invalid data entered into a form should not trigger an exception.

    Your model should have some sort of error state set, either on the model itself or on the individual fields. The post-back should “fall through” and display the same form that was originally shown, with error messages and/or highlighted fields indicating where the error is so the user can fix it.

    Throwing exceptions for validation is going to lead to a very fragile and difficult to use system. What happens if you want to simply show the user that one of the fields they supplied is invalid and give them a chance to correct it? How are you going to catch an exception and know how to display the associated record/form?

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

Sidebar

Related Questions

I'm trying to architect my MVC web project and I'm running into a bit
I was trying to download some ASP.NET MVC Sample application to learn MVC. I
I am trying to use a strong ref cur with dynamic sql statment but
it's my first use of power architect and i am trying to connect to
Im trying to use Enterprise Architect to model Oracle database. Everything is going fine,
trying to work out how to install zipArchive extension with MAMP, but not having
I'm trying to programmatically extract information from an Enterprise Architect model (saved in an
Hello stackoverflow community ! I am trying to figure out how to architect my
Trying to figure out how to do this. I have the style but I'd
I have an architect question: I want to use Tree View to display some

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.