Here is an example how to create and use custom exceptions in PowerShell. Custom exceptions provide great flexibility by being able to seperate different types for your catch statements.

Create, Inherit, & Override The Constructor:

class CustomException: System.Exception {
    CustomException([string] $x) :
        base ("This is a custom exception for: $x") {}
}

Throwing:

throw [CustomException] $x

# need to use 'new' static method if 2 parameters
throw [CustomException2]::New($x, $y)

Catching:

try {
    Invoke-Func 
} catch [CustomException1] {
    # handle errors
} catch [CustomException2] {
   # handle errors
}