DISQUS

DISQUS Hello! Huddled Masses is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Huddled Masses

Joel Bennett's development blog...
Jump to original thread »
Author

Trap [Exception] { “In PowerShell” }

Started by Jaykul · 9 months ago

Brandon and I have been talking a lot about error handling in #PowerShell (on irc.freenode.net) the last few weeks, going back and forth (and dragging half the other channel participants into the discussion) with examples and counter examples and trying to make sense of how itR ... Continue reading »

2 comments

  • I made some comentary on a Try... Catch... Finally... function at

    http://cashfoley.com/2007/10/13/TryFinallyCatch...

    The origian post is by Adam Weigert at http://weblogs.asp.net/adweigert/archive/2007/1...
  • You qualified the Try-Finally-Catch "as long as you’re able to handle all of your exceptions in a single trap".

    Actually, you can nest the Try-Finally-Catch blocks effectively.

    There are a couple of side effects I've learned and I'll blog it in the near future. In short, whenever you use a scriptblock, you effectively creates a scope for variables. As a result, varibales created or changed in a Try Section are unavailable in the Finaly or Catch scriptblocks. This is not a big deal but it might need to be anticipated. Also, this is not a specific effect from Try-Finally-Catch. It happens with all scriptblocks. This is usually managed by "dotting" the script. I just haven't found a way to work it into the Try-Finally-Catch commandlet.

    Cash Foley

Add New Comment

Returning? Login