Forum Discussion
It's time to make an exception
- Aug 06, 2023
I can't see anything wrong with your code.
The only thing that makes sense to me is that the thrown exception is not actually of the type [System.NullReferenceException], but since I can't replicate your scenario, I'm simply making an educated guess.
From a diagnostic perspective, I'd verify the exception's type inheritance manually using:
try { Connect-IMC -Name $RackServerIMCIP -Credential $IMCServerCredential -NotDefault -ErrorAction:Stop } catch { $_.Exception.pstypenames; }Where the top-most type name is the most specific to the exception, becoming less so as you read downwards.
Here's a simple example to illustrate the output:
Cheers,
Lain
I can't see anything wrong with your code.
The only thing that makes sense to me is that the thrown exception is not actually of the type [System.NullReferenceException], but since I can't replicate your scenario, I'm simply making an educated guess.
From a diagnostic perspective, I'd verify the exception's type inheritance manually using:
try
{
Connect-IMC -Name $RackServerIMCIP -Credential $IMCServerCredential -NotDefault -ErrorAction:Stop
}
catch
{
$_.Exception.pstypenames;
}
Where the top-most type name is the most specific to the exception, becoming less so as you read downwards.
Here's a simple example to illustrate the output:
Cheers,
Lain
- JulianMilanoAug 15, 2023Copper ContributorThanks Lain- that last one opens up the problem really nicely!