开发者

Database Exceptions -> Throw exceptions in Database class or in Controller class

I'm writing a j2me(mobile) which uses a db a lot. But now I don't know how to do the following.

Should I throw Exceptions in the database class itself, and use a try Catch in the controller class. Or should I use a try cat开发者_运维百科ch in the database class and return null of the object for instance wasn't stored. So on the controller class I don't have to do try catch only check if the objects exist.


It depends on your application, personally I prefer the database layer to be as transparent as possible. That means the database layer itself will be responsbile for error handling, performing rollbacks etc.

There's nothing wrong in propagating exceptions either. If your controller needs to know that something went wrong you should propagate the error. I however find this to be a bit more rare.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜