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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:09:28+00:00 2026-06-12T09:09:28+00:00

I am throwing an exception from a controller, like below try { if (formValidationResult.size()

  • 0

I am throwing an exception from a controller, like below

try {
    if (formValidationResult.size() > 0) {
        validationResults.put(errorMsg, formValidationResult);
    }
} catch (Exception exception) {
    LOGGER.error("Error while performing validation in FormController -->"
                    + exception.getMessage());
    throw new ServiceException(exception.getMessage());
}
if (validationResults.size() > 0) {
    throw new ValidationFailureException(validationResults,"Validation Error");
}

Here i am getting a validation error;

com.ge.dbt.common.exception.ValidationFailureException: Validation
Error

Can I include a catch block to catch the ValidationFailureException here?

  • 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-12T09:09:29+00:00Added an answer on June 12, 2026 at 9:09 am

    Assuming that validationResult and formValidationResult are collections, I don’t see why there is a need to enclose the call to the size and put methods in a try catch block? What exception are you expecting anyway while checking the size of these collections or inserting a new value anyway?

    I can’t give you the code because I am typing from my phone but this is what you can do :

    1. Indicate that the method containing your code throws a ValidationFailureException in the method signature.

    2. Remove the try catch block you have presented and remove the if block that checks whether validationResult is non empty and the code inside the if block.

    3. If formValidationResult is not empty, store the error message in validationResult and throw a ValidationFailureException.

    That’s it. Clean and simple. No need for any try-catch blocks and no need to separately check if validationResult is not empty before throwing a ValidationFailureException.

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

Sidebar

Related Questions

Are there any unclear side effects to throwing an exception from within a synchronized
I have a question similar to this thread : [throwing-exceptions-from-model-view-controller-in-a-zend-framework-application][1] I have a standard
I'm working with the Apache Thrift tool and i'm throwing some Exceptions from the
I can't understand why this code is throwing exception of Bad Access: - (void)viewDidLoad
What factors dictate throwing an exception if argument is null (eg if (a is
Instead of throwing new Exception(Some message, maybeSomeCause) , which means that all callers of
Why is this code throwing an exception? var dateTime = 2012-03-21_15.12; var format =
I am having trouble with XMLTextWriter.WriteStartElement throwing an exception: System.InvalidOperationException when trying to write
I'm debugging a query with .SingleOrDefault() that's throwing an exception subquery is returning more
I have a third-party library that is sometimes throwing an exception. So I decided

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.