Welcome to MSDN Blogs Sign in | Join | Help

Documenting TRAP and THROW

We pride ourselves about being a bit overboard when it comes to Error handling.  That is why our sparse (non-existing?) documentation of THROW and TRAP handling is both ironic and sad.  10,000 apologizes for that, we'll fix it in the next release. 

In the mean time, it's Don Jones amd Jeffery Hicks to the rescue.  Don and Jeffery are the co-authors of Windows PowerShell: TFM.  The great thing about that is that they decided to "give you a taste" of the book so you can see whether you might be interesting in buying it.  It is our collective good luck that they made Chapter 11 Debugging and Error Handling as the sample chapter.  Click on the Chapter in the previous sentence and it will bring you to the chapter.  If that doesn't work - go to: http://www.sapienpress.com/powershell.pdf .

BTW - their book recently went to Press so it should be available any day now.  I can't wait to get my copy.

Cheers!

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Published Friday, December 29, 2006 4:10 PM by PowerShellTeam
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Documenting TRAP and THROW

Nice but Don and Jeffery could not work out the syntax for:

Trap [ExceptionType] {

either it would seem as they don't have an example of how to express [ExceptionType]

nor does Bruce Payette

Sorry, but if they can't work it out how can I?

:J

Tuesday, April 24, 2007 6:37 PM by jeremypack

# re: Documenting TRAP and THROW

Umm.

Try this in a script file:

trap [System.DivideByZeroException] { write-host ("trapped " + $_.Exception.GetType().Name); continue; }

(1/$null)

It works just fine

Wednesday, April 25, 2007 9:56 PM by Jssmith

# Debugging Powershell

So why do you care about debugging powershell scripts? Umm unless you have the superhuman ability to

Sunday, June 24, 2007 2:58 PM by kapslock

# re: Documenting TRAP and THROW

Fyi, the sample chapters at Sapien are chapter 1 and 9 (formatting) NOT chapter 11 (trap and throw).

Wednesday, August 29, 2007 9:42 AM by scott zimmerman

# re: Documenting TRAP and THROW

I have to say it: LAME!

It's almost like you guys went out of your way to make sure that all the PowerShell developers and their buddies could make some extra money writing books to fill the voids in your documentation.

What's worse is that this is the first Google hit for powershell trap ... is there anywhere where there is *actual* document about it, instead of a broken link?

Friday, September 07, 2007 2:04 PM by Joel "Jaykul" Bennett

# re: Documenting TRAP and THROW

Friday, September 07, 2007 2:05 PM by Joel "Jaykul" Bennett

# re: Documenting TRAP and THROW

The book excerpt says "Trap handlers always execute, no matter what ErrorAction you specify"  

It seems some commands require -ea 'stop' on the command or set globally with $ErrorActionPreference = "Stop"

Tuesday, September 11, 2007 11:18 PM by jbowles

# re: Documenting TRAP and THROW

Saturday, October 13, 2007 10:23 PM by Joel "Jaykul" Bennett

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker