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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:52:26+00:00 2026-05-13T10:52:26+00:00

I use a javaBean in my jsp-application to store form values. This is how

  • 0

I use a javaBean in my jsp-application to store form values. This is how I get my values into my bean. This code is part of my form.jsp

try {  
        <jsp:setProperty name="formparam" property="*" />  
}  
catch (Exception e){ error = true; }

I left the “<%” out to not break the code display on stackoverflow. Now I get my exception if for example one puts text in my age field so the type conversation throws an exception.

Now I would like to know if it is possible to throw an exception in the setter of my bean an catch it with the very same try-catch-block.

Example form my bean: (I know this doesn’t even compile but I hope you get an idea of what I want)

public void setAge(int a) {  
    if (this.validAge(a))  
        age = a;  
    else  
        throw Exception;  
}

I hope I get my point across. Of cause it’s possible to call the validAge()-function in my bean from the form.jsp to validate the value but if I could throw an Exception directly so that the form.jsp can catch it it would be so much slicker.

So long.
mantuko

  • 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-13T10:52:26+00:00Added an answer on May 13, 2026 at 10:52 am

    1) declare the exception to be thrown
    2) “throw new Exception”

    public void setAge(int a) throws Exception {
      if (this.validAge(a))
        age =a ;
      else 
        throw new Exception("...")
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning JavaBeans and it's application I'm creating my first ever Bean, I use
Use case: 3rd party application wants to programatically monitor a text file being generated
use this website a lot but first time posting. My program creates a number
I have an assignment to use JavaBeans to create an online Banking application. I
How can I expose a Java bean to a JSP page by using struts?
I have application that look like below without spring (prior) UI-> service --> javabean
I ask this squestion on behalf of one of my developers. Haven't looked into
According to the tutorial : http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=27hibernateloadvshibernateget , If you initialize a JavaBean instance with
Why is the JavaBean standard set to use the prefix is- for a getter
I use a custom list adapter and ArrayList for my ListView. This solution was

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.