This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes usebean and catching constructor exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "usebean and catching constructor exception" Watch "usebean and catching constructor exception" New topic
Author

usebean and catching constructor exception

mark weitz
Greenhorn

Joined: Aug 08, 2001
Posts: 10
I have a case where I am using a third party bean and want to do a use:bean in my jsp. During the constructor method of the bean it attempts to connect to a server. If the connect is unsuccessful, an error is thrown. In my case, if I can't connect, that's ok, I just want to hide a button on the web page.
Unfortunately, if an error is thrown, I get a 500 rather than my webpage.
Is there a way to catch a exception thrown by a constructor when doing a use:bean?
Mark
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
The bean is not designed correctly... the constructor is meant to create and initialize the **object**, not perform business or other logic. There should've been a separate method called connect() to do that.
I guess you just have to instantiate the bean yourself with Beans.instantiate() or new() and catch the exception.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: usebean and catching constructor exception
 
It's not a secret anymore!