model view controller - Java: Error handling in MVC project. How correct implement? -
model view controller - Java: Error handling in MVC project. How correct implement? -
for example: have webapplication based on mvc
. also, app used: spring
, struts 2
, hibernate
frameworks.
lets go on little scenario: user seek save instanse, example: bo book.
so, user fill form fields , send request server:
what happened on server?
execute action methodaction.save();
inside action.save()
phone call service.save()
; inside service.save()
phone call daohibernate.save()
; inside daohibernate.save()
phone call gethibernatetemplate().save()
; method gethibernatetemplate.save()
- framework implementation, cant access method. know, if fail within method throws dataaccessexception
.
so, @ moment think, how right implement logging , error handling?
on level?
on dao level? service level?
or on level struts actions?
what think this?
or need on each level?
what best practices can recommended?
here architecture:
how want handle error on dao layer? homecoming false data? empty collection? if can't, allow exception pop-up.
and how handling on service layer? know database not working, can homecoming struts action? empty result? error object? isn't exception error object?
so exception appears in struts action. here have options. if exception tell user , gui prepared, can homecoming different view (and log exception here).
but if grab nullpointerexception
in struts action? handle separately in every struts action? no, pass exception farther (!)
i think thought - long don't know how handle exception (and logging not handling), allow client clean-up mess. otherwise hiding problem , increasing damages (e.g. transactions aren't rolled-back, users see wrong results).
i advice implementing generic exception handling mechanism logs exception , returns http 500 user. gentle error message (without stack trace) should appear , user should apologized. should investigate every error reaches layer.
as far remember struts (and virtually every web framework) has centralized way of handling exceptions. (struts 2 exception handling docs)
java model-view-controller error-handling
Comments
Post a Comment