I am learning PowerShell these days and have come across some odd behavior. After running the following code, whose only purpose is to understand exception handling:
try
{
throw [System.IO.FileNotFoundException]::new("Thrown a file not found exception")
}
catch [System.Management.Automation.RuntimeException]
{
Write-Output "Entered catch"
}
I get that "Entered catch" is shown onscreen. Why does this happen, if according to online documentation System.IO.FileNotFoundException does not have System.Management.Automation.RuntimeException in its line of inheritance? In other words, I was expecting the exception not to be caught and the corresponding exception error message to be seen onscreen instead.