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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:49:55+00:00 2026-06-02T00:49:55+00:00

I have a question in handling the business validation done on the service layer.

  • 0

I have a question in handling the “business validation” done on the service layer. The code belows shows a typical account fund transfer example, which validates for sufficient fund, transfer amount is lesser than defined limit.

In this example, the caller have to handle and catch the exception defined in the Action class and used the corresponding ActionError to display the error message.

It is a “must” to use exceptions for all business validation?

If I decide not to use exception for this, I will have to defined the corresponding ActionError in the business layer(which violates the coupling / cohesion) rule in a certain sense.

How should one handle the message propagating by service layer back to the Action classes?

public void transfer(String fromAccount, String toAccount, double amount) throws InsufficientFundsException, TransferLimitException, FactoryException { 
    try { 
        Account from = getAccountHome().findByPrimaryKey( 
new AccountKey(fromAccount)); 
        Account to = getAccountHome().findByPrimaryKey( 
new AccountKey(toAccount)); 
        if (from.getBalance() < amount) 
            throw new InsufficientFundsException(); // Add action errors

        if (from.getTransferLimit() > amount) 
            throw new TransferLimitException();  // Add action errors
        to.deposit(amount); 
        from.withdraw(amount); 
    } catch (Exception e) { 
        throw new FactoryException( 
"cannot perform transfer. Nested exception is " + e); 
    } 
}
  • 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-02T00:49:57+00:00Added an answer on June 2, 2026 at 12:49 am

    Your business should be handled in the Model and any problems encountered in your business logic should be propagated to the caller, which in this case is Struts Action classes.

    But you do not want to couple your Struts classes (Action, ActionForm, ActionError, ActionMessage etc) with the Model, so you basically have two ways of notifying the caller of any problems:

    • return some error codes that the caller can check;
    • throw some exceptions that the caller can catch.

    I prefer using exceptions because they can be thrown to the top layers from anywhere inside the business layer no matter how deep in the execution chain. This keeps the business code clean as you don’t have to bubble up error codes as it would have been the case with the first approach.

    The exceptions will then be caught by the Action class who will transform them into ActionError objects to be shown in the View. Just make sure you don’t overdo it and end up throwing the kitchen sink or your Action classes will become crowded with excessive try-catch blocks. Additionally you could let the exceptions propagate and create an exception handler of some sort that catches all exceptions thrown from below and redirects to appropriate Views based on the exception type.

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

Sidebar

Related Questions

I have an architectural question on handling message ordering. For purposes of this question,
I have a question regarding the best practise of handling formated text when using
I have a question regarding the .NET Task Parallel Library's error handling. In which
My question is related to exception handling. If i have for example three methods
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
I have a question about handling my models. I get all confused. When I
I have a query based on the answer to this question: Handling ties when
I have a question about Symbian active objects handling. What's the problem: my program
Just started with Android, and I have a question about handling images. I'm thinking
I have a question about the push notification service of the Windows Phone 7

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.