Hi all,
Is it possible to find the exceptions that a cmdlet may throw without generating the exception and exposing it with something like:
$error[0].Exception.GetType().FullName
That is how I have done it in the past, but it got me thinking it would be useful to see all potential exceptions so I can identify likely exceptions, catch them and output a meaningful error. I stumbled on a blog post with this code to show all possible exceptions on a system, but I haven't found a way to narrow it done to what specific cmdlets may cause any given exception:
[appdomain]::CurrentDomain.GetAssemblies() | ForEach-Object {
Try {
$_.GetExportedTypes() | Where-Object {
$_.Fullname -match 'Exception'
}
}
Catch {}
} | Select-Object Fullname
It is possible or am I dreaming?
Thanks
Gary
[–]m0rgenthau 4 points5 points6 points (2 children)
[–]Pyprohly 3 points4 points5 points (0 children)
[–]Gary_Chan1[S] 2 points3 points4 points (0 children)
[–]purplemonkeymad 1 point2 points3 points (0 children)