【发布时间】:2017-11-03 07:33:41
【问题描述】:
我有我的 dll,它包含函数:
function GetPdfReport(
//this is string representation of MyEnum
AStringParam : Pchar
): TByteDynArray; stdcall; export;
var
//my vars
begin
try
try
//i try to pass incorrect string value on purpose to get exception
MyEnumVariable := TRttiEnumerationType.GetValue<MyEnum>(AStringParam);
//code hide
except
on E : Exception do
begin
//log error
Log.Error(E.ClassName + ' : ' + E.Message, 'errors');
end;
end;
finally
//dispose
end;
然后我得到异常:
InnerException 消息是“无效的枚举值 '_24170”,不能 反序列化为类型 '我的枚举'。
我想要记录异常消息,其中包含我作为参数传递的字符串值,但不是一些不清楚的数字,例如“_24170”。我该怎么做?
更新:
假设我有 MyEnum 和 3 个值 (One, Two, Three),当我传递给我的函数字符串 "Five" 时,我希望看到这样的异常:
无效的枚举值“五”无法反序列化为类型“MyEnum”。
谢谢。
【问题讨论】:
-
@DavidHeffernan,看passing incorrect string,然后看exception,我的enumType不包含这个字符串