{"id":78791,"date":"2026-07-13T13:53:41","date_gmt":"2026-07-13T13:53:41","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=78791"},"modified":"2026-07-13T13:53:42","modified_gmt":"2026-07-13T13:53:42","slug":"terminating-error-vs-non-terminating-error","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=78791","title":{"rendered":"Terminating error vs non-terminating error"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Terminating error vs non-terminating error in PowerShell<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Non-terminating error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>non-terminating error<\/strong> reports a problem but allows PowerShell to continue running the remaining commands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-Content -Path \".\\MissingFile.txt\"\nWrite-Output \"The script continued.\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Possible output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-Content : Cannot find path '.\\MissingFile.txt' because it does not exist.\nThe script continued.\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The file-reading command failed, but PowerShell still ran the next line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common examples include:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-Content \".\\MissingFile.txt\"\nGet-Item \".\\MissingFolder\"\nWrite-Error \"A problem occurred\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By default, many PowerShell cmdlets generate non-terminating errors.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Terminating error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>terminating error<\/strong> stops the current operation or script block. PowerShell does not continue normally unless the error is caught.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example using <code>throw<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>throw \"The configuration file is invalid.\"\n\nWrite-Output \"This line will not run.\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The second command does not run because <code>throw<\/code> creates a terminating error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$result = 10 \/ 0\nWrite-Output \"Finished\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Division by zero produces a terminating error.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Main difference<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>Non-terminating error<\/th><th>Terminating error<\/th><\/tr><\/thead><tbody><tr><td>Displays an error<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>Continues to the next command<\/td><td>Usually yes<\/td><td>No<\/td><\/tr><tr><td>Automatically activates <code>catch<\/code><\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Can be converted using <code>-ErrorAction Stop<\/code><\/td><td>Yes<\/td><td>Already terminating<\/td><\/tr><tr><td>Typical source<\/td><td>Cmdlet failure<\/td><td><code>throw<\/code>, runtime failure, or <code>-ErrorAction Stop<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Why <code>try\/catch<\/code> sometimes does not work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Consider:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n    Get-Content -Path \".\\MissingFile.txt\"\n}\ncatch {\n    Write-Output \"The error was caught.\"\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You might expect <code>catch<\/code> to run, but <code>Get-Content<\/code> normally produces a non-terminating error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, PowerShell displays the error but may not enter the <code>catch<\/code> block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To make it catchable, add:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-ErrorAction Stop\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Correct version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n    Get-Content -Path \".\\MissingFile.txt\" -ErrorAction Stop\n}\ncatch {\n    Write-Output \"The file could not be read.\"\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now the non-terminating error is converted into a terminating error, so <code>catch<\/code> runs.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Full example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n    Write-Output \"Trying to read the file...\"\n\n    $content = Get-Content `\n        -Path \".\\MissingFile.txt\" `\n        -ErrorAction Stop\n\n    Write-Output \"The file was read successfully.\"\n}\ncatch {\n    Write-Warning \"The file could not be read.\"\n    Write-Warning \"Reason: $($_.Exception.Message)\"\n}\nfinally {\n    Write-Output \"The operation is complete.\"\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Trying to read the file...\nWARNING: The file could not be read.\nWARNING: Reason: Cannot find path ...\nThe operation is complete.\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>finally<\/code> block runs whether the operation succeeds or fails.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><code>ErrorAction<\/code> values<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many cmdlets support the common parameter <code>-ErrorAction<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-Content \".\\MissingFile.txt\" -ErrorAction Continue\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Common choices:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Value<\/th><th>Behaviour<\/th><\/tr><\/thead><tbody><tr><td><code>Continue<\/code><\/td><td>Display the error and continue; default behaviour<\/td><\/tr><tr><td><code>SilentlyContinue<\/code><\/td><td>Hide the error and continue<\/td><\/tr><tr><td><code>Stop<\/code><\/td><td>Convert the error into a terminating error<\/td><\/tr><tr><td><code>Inquire<\/code><\/td><td>Ask the user what to do<\/td><\/tr><tr><td><code>Ignore<\/code><\/td><td>Hide the error and do not add it to <code>$Error<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For exception handling, the most important one is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-ErrorAction Stop\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Write-Error<\/code> compared with <code>throw<\/code><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Write-Error<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, it creates a non-terminating error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Write-Error \"The server was not found.\"\n\nWrite-Output \"The script continued.\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To make it terminating:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Write-Error \"The server was not found.\" -ErrorAction Stop\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><code>throw<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>throw<\/code> creates a terminating error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>throw \"The server was not found.\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>throw<\/code> when the script cannot safely continue.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Simple rule<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">A non-terminating error reports a problem and usually continues. A terminating error stops normal execution and can be handled by <code>try\/catch<\/code>.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">When using a cmdlet inside <code>try<\/code>, commonly write:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n    Some-Command -ErrorAction Stop\n}\ncatch {\n    Write-Warning $_.Exception.Message\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Terminating error vs non-terminating error in PowerShell Non-terminating error A non-terminating error reports a problem but allows PowerShell to continue running the remaining commands. Example: Possible output: The file-reading command failed, but PowerShell still ran the next line. Common examples include: By default, many PowerShell cmdlets generate non-terminating errors. Terminating error A terminating error stops &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=78791\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1981],"tags":[],"class_list":["post-78791","post","type-post","status-publish","format-standard","hentry","category-power-shell","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":78793,"url":"http:\/\/bangla.sitestree.com\/?p=78793","url_meta":{"origin":78791,"position":0},"title":"Write-Error","author":"Sayed","date":"July 13, 2026","format":false,"excerpt":"Write-Error in PowerShell Write-Error writes an error message to PowerShell\u2019s error stream. By default, it creates a non-terminating error. That means PowerShell displays the error, but usually continues with the next command. Write-Error \"The file could not be found.\" Write-Output \"The script continued.\" Typical result: Write-Error: The file could not\u2026","rel":"","context":"In &quot;Power Shell&quot;","block_context":{"text":"Power Shell","link":"http:\/\/bangla.sitestree.com\/?cat=1981"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24367,"url":"http:\/\/bangla.sitestree.com\/?p=24367","url_meta":{"origin":78791,"position":1},"title":"Terminating a Hosting Account Under WHM #Root","author":"Author-Check- Article-or-Video","date":"April 7, 2021","format":false,"excerpt":"[youtube http:\/\/www.youtube.com\/watch?v=n5AX2YeZRGY] From: http:\/\/sitestree.com\/?p=3223 Categories:RootTags: Post Data:2016-01-16 20:32:12 Shop Online: https:\/\/www.ShopForSoul.com\/ (Big Data, Cloud, Security, Machine Learning): Courses: http:\/\/Training.SitesTree.com In Bengali: http:\/\/Bangla.SaLearningSchool.com http:\/\/SitesTree.com 8112223 Canada Inc.\/JustEtc: http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) Shop Online: https:\/\/www.ShopForSoul.com\/ Medium: https:\/\/medium.com\/@SayedAhmedCanada","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12190,"url":"http:\/\/bangla.sitestree.com\/?p=12190","url_meta":{"origin":78791,"position":2},"title":"WHM \u0985\u09a7\u09c0\u09a8\u09c7 \u098f\u0995\u099f\u09bf \u09b9\u09cb\u09b8\u09cd\u099f\u09bf\u0982 \u0985\u09cd\u09af\u09be\u0995\u09be\u0989\u09a8\u09cd\u099f\u09c7\u09b0  \u099f\u09be\u09b0\u09cd\u09ae\u09bf\u09a8\u09c7\u099f\u09bf\u0982 \u0964 Terminating a Hosting Account Under WHM","author":"Sayed","date":"January 17, 2016","format":false,"excerpt":"Terminating a Hosting Account Under WHM [youtube http:\/\/www.youtube.com\/watch?v=n5AX2YeZRGY] \u00a0","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78663,"url":"http:\/\/bangla.sitestree.com\/?p=78663","url_meta":{"origin":78791,"position":3},"title":"write-output vs write-host","author":"Sayed","date":"May 24, 2026","format":false,"excerpt":"Write-Output vs Write-Host in PowerShell FeatureWrite-OutputWrite-HostSends data to pipeline\u2705 Yes\u274c NoCan be stored in variable\u2705 Yes\u274c Usually noCan be redirected to file\u2705 Yes\u274c Not normally usefulUsed for script output\u2705 Recommended\u26a0\ufe0f Mainly for display messagesSupports formatting\/colorLimited\u2705 Good for colors 1. Write-Output Write-Output sends data to the PowerShell pipeline. Write-Output \"Hello PowerShell\"\u2026","rel":"","context":"In &quot;Power Shell&quot;","block_context":{"text":"Power Shell","link":"http:\/\/bangla.sitestree.com\/?cat=1981"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76475,"url":"http:\/\/bangla.sitestree.com\/?p=76475","url_meta":{"origin":78791,"position":4},"title":"Terminating Process in Linux","author":"Sayed","date":"December 8, 2024","format":false,"excerpt":"Kill a Process \u2022kill PID \u2022kill -SIGNAL PID \u2022Kill \u2013s 9 pid \u2022Kill -9 pid \u2022kill -15 PID \u2022","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16324,"url":"http:\/\/bangla.sitestree.com\/?p=16324","url_meta":{"origin":78791,"position":5},"title":"Graph Mining: Highly Connected Subgraph Clustering: Learn by finding answers to the following questions.","author":"Sayed","date":"October 14, 2019","format":false,"excerpt":"Graph Mining: Highly Connected Subgraph Clustering: Learn by finding answers to the following questions. How do you define: Highly Connected? What is a Cluster? What is Subgraph? Does connectivity indicate the number of edges between clusters? True or false: Highly connected clustering means: within a cluster, connectivity will be low.\u2026","rel":"","context":"In &quot;Graph Mining&quot;","block_context":{"text":"Graph Mining","link":"http:\/\/bangla.sitestree.com\/?cat=1905"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78791"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78791\/revisions"}],"predecessor-version":[{"id":78792,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78791\/revisions\/78792"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78791"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}