Microsoft.VisualBasic.Collection.GetEnumerator抛出一个空引用

时间:2014-05-07 01:18:10

标签: vb.net

我试图弄清楚Microsoft.VisualBasic.Collection.GetEnumerator()如何在方法中抛出Nulll Reference的异常,而不是在外面。我们有一些看起来像这样的VB.Net代码:

Dim steps As Microsoft.VisualBasic.Collection = package.GetAllSteps
If (steps.Count = 0) Then
    #Throw 
End If

For Each s As [Step] in steps 
    If s.Active = False Then
        Continue For
    End If
    #other code
Next

堆栈跟踪真的很奇怪,因为它会在GetEnumerator()内部抛出NullReference,而不是在外部。

这是堆栈跟踪:

System.Reflection.TargetInvocationException: An exception occurred during the operation, making     the result invalid. Check InnerException for exception details. 
---> System.ServiceModel.FaultException: System.Web.Services.Protocols.SoapException: Server was     unable to process request. 
---> System.Exception:  
---> System.NullReferenceException: Object reference not set to an instance of an object. 
at **Microsoft.VisualBasic.Collection.GetEnumerator()** 

编辑:对不起,我没有把事情弄清楚。我擦掉了很多未使用的代码。我想问的是,Microsoft.VisualBasic.Collection.GetEnumerator()怎么可以抛出,而不是对象本身(如果对象为null,它不会抛出对象,没有一个方法?)

0 个答案:

没有答案