Exception handling 为什么要在Sitecore中使用Assert.IsNull?

Exception handling 为什么要在Sitecore中使用Assert.IsNull?,exception-handling,try-catch,sitecore,assert,Exception Handling,Try Catch,Sitecore,Assert,我在Sitecore中看到了很多代码,其中Assert.IsNull是在任何逻辑之前使用的 e、 g Database=Factory.GetDatabase(itemUri.DatabaseName); Assert.IsNotNull(数据库,itemUri.DatabaseName); 返回database.GetItem(属性); 有人能帮我理解我为什么要使用这个吗?这个主题实际上并不特定于Sitecore,即使在这种情况下,断言方法在Sitecore库中 通常,断言用于确保您的代码在

我在Sitecore中看到了很多代码,其中
Assert.IsNull
是在任何逻辑之前使用的

e、 g

Database=Factory.GetDatabase(itemUri.DatabaseName);
Assert.IsNotNull(数据库,itemUri.DatabaseName);
返回database.GetItem(属性);

有人能帮我理解我为什么要使用这个吗?

这个主题实际上并不特定于Sitecore,即使在这种情况下,断言方法在Sitecore库中

通常,断言用于确保您的代码在开发过程中是正确的,异常处理确保您的代码能够在不可预知的情况下处理

看看这些问题,可以得到一些很好的解释

这里有一篇文章专门介绍Sitecore断言的使用: