J
Jeffrey Walton
Hi All,
I derived an EncodingException from Exception. In my code, when I
catch an OverflowException I throw a new EncodingException. The catch
and new-throw executes fine.
However, the code I am trying to guard never catches an exceptions.
The guarded code is below. I've read Jeffrey Richter's chapter on
Exceptions in CLR via C#. This behaior is neither expected nor
documented. The EncodingException class will be hung off this thread.
Any ideas why no exceptions are being caught?
Thanks,
Jeff
******************************************
int Eaten = 0;
try
{
Eaten = TryParseNested(BytesToConsume);
}
catch (EncodingException ex)
{
// Eat this exception. We are only testing if the
// the Bit String or Octet String can be parsed.
// Since we are here, it apparently cannot be parsed.
// Return -1 to screw up the math. The bad math will be
// recognized in the caller.
Debug.Print(ex.Message);
return -1;
}
catch (OverflowException ex)
{
Debug.Print(ex.Message);
return -1;
}
catch( Exception ex)
{
Debug.Print(ex.Message);
return -1;
}
******************************************
And the TryNextParse:
******************************************
int Length = 0;
try
{
Length = GetLength();
}
catch (OverflowException overflow) // <== First Caught Here
{
throw new EncodingException(InternalOffset);
}
I derived an EncodingException from Exception. In my code, when I
catch an OverflowException I throw a new EncodingException. The catch
and new-throw executes fine.
However, the code I am trying to guard never catches an exceptions.
The guarded code is below. I've read Jeffrey Richter's chapter on
Exceptions in CLR via C#. This behaior is neither expected nor
documented. The EncodingException class will be hung off this thread.
Any ideas why no exceptions are being caught?
Thanks,
Jeff
******************************************
int Eaten = 0;
try
{
Eaten = TryParseNested(BytesToConsume);
}
catch (EncodingException ex)
{
// Eat this exception. We are only testing if the
// the Bit String or Octet String can be parsed.
// Since we are here, it apparently cannot be parsed.
// Return -1 to screw up the math. The bad math will be
// recognized in the caller.
Debug.Print(ex.Message);
return -1;
}
catch (OverflowException ex)
{
Debug.Print(ex.Message);
return -1;
}
catch( Exception ex)
{
Debug.Print(ex.Message);
return -1;
}
******************************************
And the TryNextParse:
******************************************
int Length = 0;
try
{
Length = GetLength();
}
catch (OverflowException overflow) // <== First Caught Here
{
throw new EncodingException(InternalOffset);
}