![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 |
| | #1 (permalink) |
| Guest | Error Trapping : doesn't work If I do.. trap [System.DivideByZeroException] { write-host ("trapped " + $_.Exception.GetType().Name) continue } (1/$null) it works!. If I do trap [System.DivideByZeroException] { write-host ("trapped " + $_.Exception.GetType().Name) continue } (1/0) it doesn't . Yet the inner exception description for both are the same. Any thoughts ? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Error Trapping : doesn't work That happens because the expression 1/0 gets evaluated at compile time. PowerShell does 'constant expression folding', which roughly means that if there is an expression with a constant value like 1/0 (both constant values) the error is caught at compile time instead of runtime. -- Kiron |
My System Specs![]() |
| | #3 (permalink) | ||||||||||||
| Guest | Re: Error Trapping : doesn't work Thanks for the quick response. "Kiron" wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| trapping a particular type of error | andy-powershell.com | PowerShell | 4 | 08-27-2008 12:42 PM |
| Another error trapping problem | Rob Campbell | PowerShell | 2 | 01-25-2008 07:06 PM |
| trapping error messages froom get-qaduser | blittle | PowerShell | 3 | 07-09-2007 09:30 AM |
| Help w/ error trapping | Blip | PowerShell | 3 | 02-12-2007 07:34 PM |
| trapping error and then continue | IT Staff | PowerShell | 1 | 01-23-2007 03:41 AM |