![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #2 (permalink) |
| Guest | Re: How to TRY and CATCH In PowerShell you use the trap statement to handle errors. There's a little info about traps in the about_break help file as well as in the Tri-fold reference that's installed with PowerShell (just the basic structure of the trap statement really). A better source is the PowerShell team blog. There's a four or five part series about error handling in (at the time Monad, but it all still holds true) PowerShell. You can find the first blog in the series here: http://blogs.msdn.com/monad/archive/...04/489138.aspx Tom G. -- John Smith wrote: > HELP ABOUT_TRAP produces nothing. Scanning output of HELP for TRAP > and EXCEPTION produces nothing. > > How do I handle exceptions in Windows PowerShell? > > Thanks. |
| | #3 (permalink) |
| Guest | Re: How to TRY and CATCH Thanks. But can't find part 9 which talks about trapping errors. "Tom G." wrote: > A better source is the PowerShell team blog. There's a four or five > part series about error handling in (at the time Monad, but it all > still holds true) PowerShell. You can find the first blog in the series > here: http://blogs.msdn.com/monad/archive/...04/489138.aspx > > Tom G. > -- |
| | #4 (permalink) |
| Guest | Re: How to TRY and CATCH Found the article. But it's by examples. What goes into the [ ]? I tried[*] and it didn't work. I tried [] and it didn't work either. In a function, it appears that RETURN or BREAK in a TRAP block does not exit the function: PS C:\> function validate-imagefile([String]$file) >> { >> trap [System.SystemException] { >> write-host "Error is " $_ -foreground green >> return (1 -eq 2); } >> $img = New-Object -typename System.Drawing.Bitmap -ArgumentList $file >> Remove-variable img >> return (1 -eq 1) >> } >> validate-imagefile("xxx") >> Error is Exception calling ".ctor" with "1" argument(s): "Parameter is not valid." New-Object : Exception calling ".ctor" with "1" argument(s): "Parameter is not valid." At line:6 char:20 + $img = New-Object <<<< -typename System.Drawing.Bitmap -ArgumentList $file Remove-Variable : Cannot find a variable with name 'img'. At line:7 char:18 + Remove-variable <<<< img False True |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Newsgroups won't catch up | John R | Vista mail | 12 | 05-09-2008 08:00 AM |
| Try Catch | Brian | .NET General | 2 | 04-12-2008 12:48 PM |
| catch-up | John A Grandy | Vista mail | 0 | 03-02-2008 07:53 PM |
| Catch-all | Greg23 | PowerShell | 4 | 08-14-2007 02:18 AM |
| I Catch VI | Jason | Vista hardware & devices | 0 | 10-03-2006 07:01 PM |