You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Charlie Toohey <ct...@pacbell.net> on 2002/09/11 20:42:29 UTC
Handing bean errors in Action class (per Struts Users Guide)
The Struts User's Guide advocates the following (section 4.2), with respect
to how exceptions/errors in beans called by Action classes should be handled
by the Action class :
"The beans that represent the Model of your system may throw exceptions due
to problems accessing databases or other resources. You should trap all such
exceptions in the logic of your perform() method, and record them in the
application's log (along with the corresponding stack trace) by calling:
servlet.log("Error message text", exception); "
This seems very odd to me. I would expect to write a bean that fully
encapsulates all database activity, including all exception handling, closing
statements, result sets, connections, etc. before returning to the Action
perform method. But the Struts Users Guide is advocating handling exceptions
from the bean in the Action perform method --- which means that the Action
class perform method would include database code, which is clearly
undesireable, from the perspective of a reusable bean and separation of
roles. Or , am I wrong here ??
It would seem to me that the best way to maintain a separation between the
Struts Action and the database code would be to have bean methods which
handle all exceptions within the bean and then return a result code, rather
than throwing unhandled exceptions.
Any comments ?
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>