BLL 错误最佳实践

发布于 2024-07-23 00:27:39 字数 75 浏览 6 评论 0原文

在 BLL 中返回业务规则错误的最佳实践是什么? 我是否应该引发异常并在表示层中捕获它们,是否应该返回某种包含任何异常类型信息的对象?

What is the best practise for returning an error of a business rule in a BLL? SHould I just raise exceptions and catch them in the presentation layer, shoudl I return some kind of object that holds any exception type info?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2024-07-30 00:27:39

“归来”这个词在这里很棘手。

多层设计的主要优点是正交性。 您应该能够从与当前使用的 UI 完全不同的 UI 中调用 BLL 中的类,并以完全不同的方式处理日志记录。

如果无需用户干预或通知即可处理异常,则通常应在 BLL 内进行处理。 如果需要引起用户注意或记录异常,则让它冒泡到 UI,UI 可以实现通知和日志记录,而无需将此类内容构建到 BLL 中。

The word "returning" is tricky here.

The primary virtue of multi-tier design is orthogonality. You should be able to call the classes in your BLL from an entirely different UI than the one you're currently using and handle logging completely differently.

If an exception is able to be handled without user intervention or notification, you should generally do so within the BLL. If the exception needs to be brought to the user's attention or logged, let it bubble up to the UI, which can implement notification and logging without building such things into the BLL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文