/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Strange behavour of get-member on DataTables "," CodeSigning in Monad" Shell Beta 2 (for .NET Frame... "," WMI viewer script for MSH (GUI) "," Monad Release for Whidbey RTM "," Thow Dices in MSH "," when to change your clock ? ask Monad !! "," AD Infastructure exploring with MSH "," Get Current dir in MSH consoleTtitle "," MSH ASCII translator "," red MSH> prompt "," ")

Monday, October 31, 2005

 


MSH Error message line number and Trap.



An Other issue that did cost me a lot of time was that if you trap an Error,
and there is an Error in the TRAP MSH will point you at the wrong place
(at the foreach, that had the trap in it.)

See example below.

as my function was a bit bigger,and I did not have the helper Writes ($_.name and "Trap") that I put in the Example to point me the way. ( WMI viewer script for MSH (GUI) ), It took me some time to find this out.

So don't make errors in your TRAP's !!!

gr /\/\o\/\/

PS I know that it is a bit ugly this way, but still the error is confusing.
(in productioncode I would check first and not Trap the Error)

$MC = new-object system.management.ManagementClass win32_share
$MOC = $MC.GetInstances()
$MOC foreach {
$_.name
$null.name() = "Trap Me Please"
trap{"Trap";$null.name() = "Find Me Please"}
}
 
E$
Trapforeach-object : You cannot call a method on a null-valued expression.
At line:1 char:15
+ $MOC  foreach  <<<< {
 



Comments: Post a Comment

Links to this post:

Create a Link



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?