Gary
2010-03-30 14:16:08 UTC
Hi there
Today at lunch I tried to learn how to try and catch an exception.
I've been wanting to learn how to read the registry in prep for the
Scripting Games :)
Anyway I can't seem to catch the exact exception I can only catch the
generic system.exception even thought $error tell me I have write name.
Could someone else try for me
<code>
$ErrorActionPreference = "stop"
Try { Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\" -Name Wallpaper2 }
Catch [System.Management.Automation.PSArgumentException] { "caught a
PSArgumentException" }
Catch [system.exception] { "caught a system.exception" }
Finally { "end of script" }
</code>
$error display's
SMessageDetails :
Exception : System.Management.Automation.PSArgumentException:
Prope
rty Wallpaper2 does not exist at path
HKEY_CURRENT_USER
\Control Panel\Desktop\.
TargetObject : Wallpaper2
CategoryInfo : InvalidArgument: (Wallpaper2:String)
[Get-ItemProperty]
, PSArgumentException
FullyQualifiedErrorId :
System.Management.Automation.PSArgumentException,Micros
oft.PowerShell.Commands.GetItemPropertyCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
PipelineIterationInfo : {0, 1}
Is anyone able to help me understand where I'm going wrong?
TIA
Today at lunch I tried to learn how to try and catch an exception.
I've been wanting to learn how to read the registry in prep for the
Scripting Games :)
Anyway I can't seem to catch the exact exception I can only catch the
generic system.exception even thought $error tell me I have write name.
Could someone else try for me
<code>
$ErrorActionPreference = "stop"
Try { Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\" -Name Wallpaper2 }
Catch [System.Management.Automation.PSArgumentException] { "caught a
PSArgumentException" }
Catch [system.exception] { "caught a system.exception" }
Finally { "end of script" }
</code>
$error display's
SMessageDetails :
Exception : System.Management.Automation.PSArgumentException:
Prope
rty Wallpaper2 does not exist at path
HKEY_CURRENT_USER
\Control Panel\Desktop\.
TargetObject : Wallpaper2
CategoryInfo : InvalidArgument: (Wallpaper2:String)
[Get-ItemProperty]
, PSArgumentException
FullyQualifiedErrorId :
System.Management.Automation.PSArgumentException,Micros
oft.PowerShell.Commands.GetItemPropertyCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
PipelineIterationInfo : {0, 1}
Is anyone able to help me understand where I'm going wrong?
TIA