{"id":798,"date":"2014-08-21T11:59:00","date_gmt":"2014-08-21T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/08\/21\/powertip-mini-scripting-games-2014-answer-4\/"},"modified":"2014-08-21T11:59:00","modified_gmt":"2014-08-21T11:59:00","slug":"powertip-mini-scripting-games-2014-answer-4","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-mini-scripting-games-2014-answer-4\/","title":{"rendered":"PowerTip: Mini-Scripting Games 2014 Answer 4"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Here is the answer to the fourth question in Mini-Scripting Games&nbsp;2014.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;You are attempting to use Try\/Catch\/Finally in your script. No matter what you try, <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the script never seems to catch it. What is the most likely cause of the problem?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;The most likely cause of the problem is that your&nbsp;<b>Try<\/b>&nbsp;statement does not generate a terminating error, <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and therefore, there is nothing for&nbsp;<b>Catch<\/b>&nbsp;to catch.<\/p>\n<p style=\"margin-left:60px\">&nbsp;One easy way to fix this is to change your&nbsp;<b>$ErrorActionPreference<\/b>&nbsp;variable from&nbsp;<b>Continue<\/b>&nbsp;to&nbsp;<b>Stop<\/b>.<br \/><span style=\"font-size:12px\">&nbsp;This will cause your non-terminating errors to actually terminate and send <\/span><span style=\"font-size:12px\">the control to the&nbsp;<br \/><\/span><b style=\"font-size:12px\">&nbsp;Catch<\/b><span style=\"font-size:12px\">&nbsp;portion of your script.<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" alt=\" \" border=\"0\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Here is the answer to the fourth question in Mini-Scripting Games&nbsp;2014. &nbsp;You are attempting to use Try\/Catch\/Finally in your script. No matter what you try, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the script never seems to catch it. What is the most likely cause of the problem? &nbsp;The most likely cause of the problem [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[356,3,45],"class_list":["post-798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Here is the answer to the fourth question in Mini-Scripting Games&nbsp;2014. &nbsp;You are attempting to use Try\/Catch\/Finally in your script. No matter what you try, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the script never seems to catch it. What is the most likely cause of the problem? &nbsp;The most likely cause of the problem [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}