PowerShell - Why “Divide By Zero Exception” is not being Caught?

Question!

On my Machine each one of the following code snippets throws and exception instead of printing to the standard output "1" and "2" Why the exception is not being Caught?

try {
    [int]$a = 1/0
}
catch {
    write 1
}
finally {
    write 2
}

try {
    [int]$a = 1/0
}
catch [System.Exception] {
    write 1
}
finally {
    write 2
}
By : Oz Molaim


Answers

You can try to throw an exception with that kind of line : trap { "Your Exception" } 1/0
This will throw the exception "divide by 0". Though I don't really understand why your code doesn't throw an exception ._.
PS : Isn't that supposed to be catch [System.SystemException] ? :)

By : Depado


This video can help you solving your question :)
By: admin