This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes ActionError vs. ActionMessges Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionError vs. ActionMessges Question" Watch "ActionError vs. ActionMessges Question" New topic

ActionError vs. ActionMessges Question

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I have a basic Struts application connected to a MySQL database. At a high level, I have methods in my error handling that captures SQLExceptions and based on the error code, I generate user-friendly error messages. I generate these friendly messages by creating ActionMessages and adding them to the ActionMessage object which is then added to ActionError object with the addErrors method.

My question is, in my catch block, I can access the MySQL error code, but not the message. Basically, if I pass the SQLException into my catch block as (SQLException ex), then ex.getErrorCode has a value but ex.getMessage (as well as ex.getLocalizedMessage) come up null. How do I access the actual message itself?

One other thing: in my html:errors tag on the resulting error page, the MySQL error message appears! Where does that come from? How do I access that message before my screen is generated?

Don't get me started about those stupid light bulbs.
subject: ActionError vs. ActionMessges Question
Similar Threads
print StackTrace in finally block
Loading from in Struts 2
Exception Handling
ActionErrors and error message from legacy system help needed
try..catch block