断言不能被发现。这很好,因为我不想在try/catch中包含一些错误,至少不是在开发服务器上。但断言看起来非常危险。如果他们进入生产环境,它可以用msgbox挂起ASP.NET服务器。如何在ASP.NET中安全地Debug.Assert?
//Don't want this on prod even if debug=true is in the web.config
#if DEBUG
//A future client programmer can wrap this in a try{}catch{}
if (!EverythingIsOkay)
throw new InvalidOperationException("Dagnabbit, programming error");
//This stops the but has less information that an
// Exception and hangs the server if this accidentally
// runs on production
System.Diagnostics.Debug.Assert(!EverythingIsOkay);
#endif
有没有更好的方法来沟通违反不受侵犯的条件的开发人员没有挂IIS风险?
UPDATE:看完第一篇后,我想答案取决于一个万无一失的方法,当代码在开发环境中运行,并检测时,它是在生产服务器上,或搞清楚如何抛出一个异常不能被发现和忽略。
总是部署发布版本? – driis 2010-04-07 20:38:28
@driiis错误发生了,我的继任者不会像我一样聪明。为什么要构建陷阱和炸弹? – MatthewMartin 2010-04-07 21:31:14