Exceptions and ErrorRecords, for whatever reason, need to have the -Force switch used when you pipe them to Format-List and such. I forget why that is, but PowerShell really really wants to display them the way it thinks they should be displayed. 🙂
To get the type of the exception, $_.Exception.GetType().FullName should suffice.
That would be very unusual, but not impossible. .NET code (including PowerShell cmdlets) generally considers it a bad practice to just throw the base exception class, rather than subclassing it to something more useful that can be caught and handled specifically.
The topic ‘Get the class of an exception and catch it’ is closed to new replies.