【发布时间】:2012-05-05 00:48:29
【问题描述】:
在开发模块化应用程序时,很明显我们需要使用Fail-fast 系统吗?
在创建模块时,如果出现模块无法处理的错误情况,它应该报告错误(比如抛出异常..),而不用担心谁来处理它。看起来这可以作为开发模块时的指南。这有什么问题吗?
编辑:示例
在module.dll中
public class SomeClass:ISomeInterface
{
public void CreateFile(string filename)
{
//The module have no idea who calls this. But there is something wrong
//somewhere so throw an exception early. The module writer has no control over
//how the exception is handled. So if this exception is not handled by the
//Client Application the application can potentially crash.Do he need to worry
//about that?
if(filename == null)
{
throw new ArgumentNullException("Filename is null");
}
//I think the following is bad. This code is making sure that a module
//exception wont crash the application.Is it good?
//if(filename ==null)
//{
//Logger.log("filename is null");
//return;
//}
}
}
【问题讨论】:
标签: c# wpf exception-handling error-handling modularity