![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
|
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | PSH Guru needed ! : Trapping terminating errors When I try this trap { "Got it : division by zero !" } 1/$null; "next" The trap is working successfully : Got it : division by zero ! Tentative de division par zéro. Au niveau de ligne : 1 Caractère : 44 + trap { "Got it : division by zero !" } 1/$ <<<< null; "next" But when I try this (who's the same thing in theory) : trap { "Got it : division by zero !" } 1/0; "next" I got : Tentative de division par zéro. Au niveau de ligne : 1 Caractère : 44 + trap { "Got it : division by zero !" } 1/0 <<<< ; "next" And my trap is not working !!! What's wrong !? I have a big headhache with that problem ! Please help me ! Arnaud Petitjean http://www.powershell-scripting.com The PowerShell's French Community |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: PSH Guru needed ! : Trapping terminating errors 1/0 fails at compile time, so nothing is wrong, don't worry ![]() -- Thanks, Roman Kuzmin PowerShellFar and FarNET: http://code.google.com/p/farnet/ |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: PSH Guru needed ! : Trapping terminating errors The trap works when division by a variable which's value is zero. I'm no guru though ![]() $zero = 0 trap { "Got it : division by zero !" } 1/$zero; "next" ....or in the pipe: 1,6,9,0 | foreach-object {trap { "Got it : division by zero !" } 1/$_ }; "next" -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: PSH Guru needed ! : Trapping terminating errors <PowerShell In Action> metioned this case, I paste the Author note here: The example here uses 1/$null. The reason for doing this instead of simply 1/0 is because the PowerShell interpreter does something called constant expression folding. It looks at expressions that contain only constant values. When it sees one, it evaluates that expression once at compile time so it doesn¡¯t have to waste time doing it again at runtime. This means that impossible expressions, such as division by zero, are caught and treated as parsing errors. Parsing errors can¡¯t be caught and don¡¯t get logged when they¡¯re entered interactively, so they don¡¯t make for a good example. (If one script calls another script and that script has one of these errors, the calling script can catch it, but the script being parsed cannot.) "A. Petitjean" <APetitjean@discussions.microsoft.com> news:E32C470A-9D56-498C-837B-F15C2A06147B@microsoft.com... > When I try this > trap { "Got it : division by zero !" } 1/$null; "next" > > The trap is working successfully : > Got it : division by zero ! > Tentative de division par z¨¦ro. > Au niveau de ligne : 1 Caract¨¨re : 44 > + trap { "Got it : division by zero !" } 1/$ <<<< null; "next" > > But when I try this (who's the same thing in theory) : > trap { "Got it : division by zero !" } 1/0; "next" > > I got : > Tentative de division par z¨¦ro. > Au niveau de ligne : 1 Caract¨¨re : 44 > + trap { "Got it : division by zero !" } 1/0 <<<< ; "next" > > And my trap is not working !!! > > What's wrong !? I have a big headhache with that problem ! Please help me ! > > Arnaud Petitjean > http://www.powershell-scripting.com > The PowerShell's French Community |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: PSH Guru needed ! : Trapping terminating errors Ah Ok, I understand now ! Thanks a lot for your help. Arnaud "Edengundam" wrote: > <PowerShell In Action> metioned this case, I paste the Author note here: > > The example here uses 1/$null. The reason for doing this instead of simply > 1/0 is because the PowerShell interpreter does something called constant > expression folding. It looks at expressions that contain only constant > values. When it sees one, it evaluates that expression once at compile time > so it doesn¡¯t have to waste time doing it again at runtime. This means that > impossible expressions, such as division by zero, are caught and treated as > parsing errors. Parsing errors can¡¯t be caught and don¡¯t get logged when > they¡¯re entered interactively, so they don¡¯t make for a good example. (If > one > script calls another script and that script has one of these errors, the > calling > script can catch it, but the script being parsed cannot.) > > "A. Petitjean" <APetitjean@discussions.microsoft.com> > news:E32C470A-9D56-498C-837B-F15C2A06147B@microsoft.com... > > When I try this > > trap { "Got it : division by zero !" } 1/$null; "next" > > > > The trap is working successfully : > > Got it : division by zero ! > > Tentative de division par z¨¦ro. > > Au niveau de ligne : 1 Caract¨¨re : 44 > > + trap { "Got it : division by zero !" } 1/$ <<<< null; "next" > > > > But when I try this (who's the same thing in theory) : > > trap { "Got it : division by zero !" } 1/0; "next" > > > > I got : > > Tentative de division par z¨¦ro. > > Au niveau de ligne : 1 Caract¨¨re : 44 > > + trap { "Got it : division by zero !" } 1/0 <<<< ; "next" > > > > And my trap is not working !!! > > > > What's wrong !? I have a big headhache with that problem ! Please help me > ! > > > > Arnaud Petitjean > > http://www.powershell-scripting.com > > The PowerShell's French Community > > > |
My System Specs![]() |
|
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trapping WMI remoting errors and continuing on. | Steve Schofield | PowerShell | 4 | 08-12-2008 09:43 PM |
| Wierd disaster! I need a guru - PLEASE | notachance | Vista General | 13 | 11-03-2007 09:48 AM |
| Powershell TRAP for non-terminating errors | mpriem | PowerShell | 0 | 03-23-2007 05:20 AM |
| Wooly concepts? Terminating and non-terminating errors. | Andrew Watt [MVP] | PowerShell | 0 | 11-13-2006 04:29 PM |
| Validation needed: Tabular output throws OutofMemoryException errors with Out-File -Width 0x7fffffff | Alex K. Angelopoulos [MVP] | PowerShell | 5 | 06-28-2006 06:49 AM |