• Blog
  • Contact
  • About
Menu

The PowerShell Bear

I'm here to help you!
  • Blog
  • Contact
  • About
Don't let your scripts get out of hand

Don't let your scripts get out of hand

Error Handling: Basic Primer

December 26, 2017

It happens: you run a script or execute a command, and something doesn't work quite right.  You get an ugly red error.  Now what?

There are many ways to handle this.  When you're sitting at the console, frequently it comes down to simply reading the error message and figuring out what you forgot or mistyped.  These are often the easiest errors to deal with just for the fact that they're interactive by nature, so you get the opportunity to try other things until you get the results you're looking for before proceeding.

Things get a lot more complicated, however, when you're writing a script, especially one that is meant to run without someone sitting at a console to see the errors.  At least if the script is being run manually, the person sitting at the console will be able to see that something did go wrong; when it's unattended, though, frequently you wind up losing valuable clues as to what went wrong, so you need to think about how your script could fail and account for that ahead of time with error handling.

Read More
In Tips and Tricks, Fundamental Learning Tags Error, Error Handling, Try/Catch, Throw, Automatic Variables, Streams
Comment

Latest Posts

Blog
Using Visual Studio Code Syntax highlighting to make PowerShell better
about 3 years ago
"PoshMailKit" Release version 1.1.0 published to Gallery
about 3 years ago
"PoshMailKit" version 0.9.1-beta2 published to Gallery
about 3 years ago
New project announcement: "PoshMailKit"
about 3 years ago
Change Report: 2021
about 4 years ago

Fresh Tweets

Whatever it is, the way you tell your story online can make all the difference.
  • #PowerShell #PoshMailKit, based on #MailKit, version 1.1.1 published to the #PowerShellGallery:… https://t.co/hj3WHKq5A9
    Jun 29, 2022, 1:54 PM
  • Using Visual Studio Code Syntax highlighting to make PowerShell better https://t.co/XoFrFonUQ9 #PowerShell #VSCode #SyntaxHighlighting
    Apr 26, 2022, 4:45 PM
  • "PoshMailKit" Release version 1.1.0 published to Gallery https://t.co/MNbDLtu8VG #PowerShell #SendMailMessage #MailKit #PoshMailKit
    Apr 20, 2022, 12:59 PM
  • "PoshMailKit" version 0.9.1-beta2 published to Gallery https://t.co/BUBdaYn86a #PowerShell #SendMailMessage #MailKit #PoshMailKit
    Mar 14, 2022, 10:55 AM
  • New project announcement: "PSMailKit" https://t.co/o3kme1upaE #PowerShell #SmtpClient #Send-MailMessage #MailKit
    Mar 8, 2022, 6:54 PM

Powered by Squarespace