开发者

Best approach of handling exceptions in Struts2?

开发者 https://www.devze.com 2023-02-15 18:16 出处:网络
Can anybody tell me the best approach of handling exceptions in Struts2? I\'ve configured global exception mappings in struts.xml for specific exceptions. I couldnt find the best approach of handling

Can anybody tell me the best approach of handling exceptions in Struts2? I've configured global exception mappings in struts.xml for specific exceptions. I couldnt find the best approach of handling exceptions.I have two approaches in mind. 1) putting try/catch in each method and throwing exceptions from catch block 2)Without catching any exceptions ie.开发者_开发问答, declaring exceptions in throws clause of method so that Framework automatically handles exceptions and picks suitable mapping from struts.xml and displays the respective error page.

If anybody knows or has tutorial link on this exception handling, pls provide me.


Catching and subsequently rethrowing an exception is almost never a good idea. Typically, you only want to have try/catch blocks if there is actually something you can do with the caught exception, such as handle it and move on correctly, or adding additional information to the exception.

Adding throws to a struts method is perfectly acceptable, in the event that what it throws is not something you can handle in your code and you just need to display an error page. Unless there is some gain to the overhead of the try/catch, it is better just to let it unwind on out on it's own.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号