PowerShell - Why “Divide By Zero Exception” is not being Caught?
问题 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 } 回答1: As you are using constants, the interpreter tries to precompute the result and fails with a division by zero error. Your code does not even get executed so there's nothing to trap. You