在开发模块化应用程序时,我们需要使用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;
//}
}
}