Error Control Help Please!!!

Halonix

Member
Joined
Aug 7, 2004
Messages
8
Programming Experience
3-5
Im confused... MSDN says the enumvalue method will return either a integer 0 or a non-zero error code. Why is it that when I run this code:

VB.NET:
Dim code As Integer

oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!" & p_SystemPath & "\root\default:StdRegProv")
code = oReg.EnumValues(regHive, regPath, arrSubKeys)
on a machine that doesnt exist that I get an invalidcast exception and "code" still equals to 0? here is all the code(this is not in use yet, I must messing around with it tryinng to understand it better):
VB.NET:
            Try
                Dim strKeyPath As String
                Dim arrSubKeys As Array
                Dim subkey As String
                Dim code As Integer

                oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!" & p_SystemPath & "\root\default:StdRegProv")
                code = oReg.EnumValues(regHive, regPath, arrSubKeys)
                Console.WriteLine("Enum Suceeded: " & code)
                Return arrSubKeys
                oReg = Nothing
            Catch invalidcast As System.InvalidCastException
                Console.WriteLine("Enum Failed: " & code)
                Console.WriteLine(invalidcast.StackTrace)
            End Try
Code is dim'ed public up further in the code.
 

Halonix

Member
Joined
Aug 7, 2004
Messages
8
Programming Experience
3-5
Nevermind I figured it out... the problem was that I was casting arrSubKeys as an Array. However when there was no keys to enumerate arrSubKeys returned as a Null value instead. So what I did was removed the casting for that variable. Im not sure if there is any disadvantage to this but it seems to work. Is there a way to cast a variable as dbnull or array?
 
Top Bottom