{"id":10911,"date":"2006-04-25T12:17:50","date_gmt":"2006-04-25T12:17:50","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/04\/25\/debugging-monad-scripts-part-1-teminating-vs-non-terminating-errorrecord\/"},"modified":"2019-02-18T13:25:06","modified_gmt":"2019-02-18T20:25:06","slug":"debugging-monad-scripts-part-1-teminating-vs-non-terminating-errorrecord","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/debugging-monad-scripts-part-1-teminating-vs-non-terminating-errorrecord\/","title":{"rendered":"Debugging Monad Scripts, Part 1: Teminating vs. Non-Terminating, ErrorRecord"},"content":{"rendered":"<p>Did your command or script fail and\/or report an error?&nbsp; We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong.&nbsp; In this series of blog entries, I will present some of those features.&nbsp; Thanks to Jim Truher [MSFT], Bruce Payette [MSFT], and Jeff Jones [MSFT] for their help in putting this together.<\/p>\n<p>See the Windows &#8220;Monad&#8221; Shell Beta 2 Documentation Pack (<a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=8a3c71d1-18e5-49d7-952a-c55d694ecee3&amp;displaylang=en\">http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=8a3c71d1-18e5-49d7-952a-c55d694ecee3&amp;displaylang=en<\/a>) for general information about Monad.<\/p>\n<p>The following is a tentative table of contents for this series of blog entries:<\/p>\n<ul>\n<li><strong>Terminating vs. Non-Terminating Errors<\/strong>\n<li><strong>ErrorRecord<\/strong>\n<li><strong>$error<\/strong>\n<li><strong>Write-Host<\/strong>\n<li><strong>Set-Mshdebug [-Trace 0..2] [-Step] [-Off]<\/strong>\n<li><strong>Preferences and Commandline Options<\/strong>\n<li><strong>Trace-Expression<\/strong>\n<li><strong>Breakpoint Script<\/strong>\n<li><strong>How Traps Work<\/strong><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Terminating vs. Non-Terminating Errors<\/strong><\/p>\n<p>Before we start in with debugging, let&#8217;s do a quick refresher on how MSH reports errors.&nbsp; Errors are fundamentally divided into &#8220;terminating&#8221; and &#8220;non-terminating&#8221;, where terminating errors terminate the command (and sometimes the entire script), while non-terminating errors are generally just reported.&nbsp; In either case, there are ways you can configure how errors are managed.&nbsp; In general, operational errors (e.g. insufficient permissions to delete a file) are usually non-terminating, while most script bugs (e.g. syntax errors) are usually terminating.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>ErrorRecord<\/strong><\/p>\n<p>Errors are represented by a System.Management.Automation.ErrorRecord object.&nbsp; The ErrorRecord object contains an Exception, plus other handy information for understanding the error and the context in which it occurred.&nbsp; The properties of ErrorRecord are:<\/p>\n<p><font face=\"Courier New\">Exception<\/font>: This is the error which occurred.<br \/><font face=\"Courier New\">TargetObject<\/font>:&nbsp; This may be null.&nbsp; TargetObject is the object which was being operated on (file, service etc.) when the error occurred.<br \/><font face=\"Courier New\">CategoryInfo<\/font>:&nbsp; This divides all errors into a few dozen broad categories.<br \/><font face=\"Courier New\">FullyQualifiedErrorId<\/font>:&nbsp; This identifies the error condition more specifically than either the ErrorCategory or the Exception.&nbsp; Use FullyQualifiedErrorId to filter highly specific error conditions.<br \/><font face=\"Courier New\">ErrorDetails<\/font>:&nbsp; This may be null.&nbsp; If present, ErrorDetails can specify additional information, most importantly ErrorDetails.Message which (if present) is a more exact description and should be displayed instead of Exception.Message.<br \/><font face=\"Courier New\">InvocationInfo<\/font>:&nbsp; This may be null.&nbsp; InvocationInfo tells you about the context in which the error occurred &#8212; the cmdlet name, script line number etc.<\/p>\n<p>[<i>Edit: Monad has now been renamed to Windows PowerShell.  This script or discussion may require slight adjustments before it applies directly to newer builds.<\/i>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did your command or script fail and\/or report an error?&nbsp; We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong.&nbsp; In this series of blog entries, I will present some of those features.&nbsp; Thanks to Jim Truher [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10911","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Did your command or script fail and\/or report an error?&nbsp; We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong.&nbsp; In this series of blog entries, I will present some of those features.&nbsp; Thanks to Jim Truher [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10911","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=10911"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10911\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=10911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}