本文介绍了在图书馆异常处理政策的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建.NET库,什么是你的异常处理政策?在具体的,什么是你对处理内部库调用异常并将它们暴露在调用代码政策?



例如,




  • 您会给予的库函数的任何其他,从而让所有的异常不能处理流出它就好了?

  • 你创造该库自定义异常?

  • 您会捕获所有异常并抛出图书馆的例外呢?你设置原始异常作为库的异常内部异常?

  • 将如何在DB库的依赖会影响您的异常处理政策?



你会建议对异常处理在.NET库?


解决方案

Yes, this is definitely the default strategy.

Yes, if callers can conceivably do something about the situation and to do so they need to be able to distinguish the exception from other exceptions. But that's pretty rare.

A database dependency might entail exposing settings that let callers specify how the library handles certain exceptions (e.g., MaximumDeadlockRetries).

No, not all exceptions. For specific exceptions, it's remotely possible, though the only case I can think of where I might want to do this is when my library has already tried to handle the exception (as in the database scenario above) and failed.

这篇关于在图书馆异常处理政策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:00