Build and Throw Custom Exception Classes in PowerShell

preview_player
Показать описание
Did you know that you can build your own custom exception (error) classes in PowerShell? It's true, thanks to PowerShell being built on the .NET Framework, and supporting class definitions, you can inherit from the System.Exception class and make your own exceptions. The goal of this video is to demonstrate how to create and use an exception class.

By creating your own exception classes, you can make errors much more meaningful to anyone who's debugging your application.

Producer: Trevor Sullivan

#PowerShell #DevOps #Microsoft
Рекомендации по теме
Комментарии
Автор

I found this video really useful, Trevor. Thank you for taking the time to create it.

I created a custom exception class based upon this and it is working for the most part. The problem I have is when it is contained within a PowerShell module, and then throwing it to the caller of the function when a condition is met. Essentially, it states that it cannot find the custom class. If I call the class ps1 file containing it and then use the function, the exception is successfully thrown. I think I have to export the class in the same way I would do a public function in a module, but not sure if that is what I should be doing.

Can you recommend or point me towards where I could determine the answer, please?

JimRoberts
visit shbcf.ru