I'm creating a .NET assembly that needs to be COM callable from e.g. VB6 etc.
Most of the stuff works fine - I'm fine-tuning my error handling right now.
What I'd like to do is create specific HRESULT
values for my exceptions - e.g. use values like 0x88880001
etc. for my exception cases.
I'd like to use a common "prefix" (like 0x8888
) and then add my internal error codes (running from decimal 1001 up) to that number.
So my internal error 1001 should become HRESULT = 0x888803E9
and so forth.
I have my own custom .NET exception class, and I know I can set the protected HResult
property on the base ApplicationException
class - but somehow I can't manage to get my "prefix" plus my error code to work....
using System;
public class CustomException : ApplicationException
{
public CustomException(string message, int errorCode) : base(message)
{
base.HResult = (uint) 0x88880000 + errorCode;
}
}
No matter what I try here - I just cannot get a int
value (for base.HResult
, which is an int
) that represents 0x888803E9
to be stored into my base class...
What am I missing here??