【发布时间】:2020-05-04 02:23:08
【问题描述】:
在尝试通过 PropertyAccessor 获取属性之前,是否有测试属性是否存在的方法?
我利用下面的函数,使用 Outlook PropertyAccessor,返回属性的字符串值。如果该属性不存在,该函数将捕获错误并返回一个空值字符串。我使用 debug.writeline 方法写出错误以明显识别抛出的错误 - 我真正遇到的唯一错误是 Exception throw: 'System.Runtime.InteropServices.COMException 并且通常是与未知或无法找到的财产有关。传递的 DASL 和属性名称正确且有效 - 但并非所有电子邮件都具有这些属性 - 它们是由独立软件供应商创建的。
...
using Outlook = Microsoft.Office.Interop.Outlook;
...
private string GetPropertyString(Outlook.PropertyAccessor pa, string property)
{
string retVal = null;
try
{
retVal = (string)pa.GetProperty(property);
}
catch (Exception ex)
{
retVal = null;
Debug.WriteLine("OutlookProperties - GetPropertyString() - Error:=" + ex.Message);
//throw;
}
finally
{
}
return retVal;
}
当一个属性不存在时,抛出一个异常,当它被捕获时,它似乎没有(正确)处理 - 输出是:
抛出异常:Office777.dll 中的“System.Runtime.InteropServices.COMException”
OutlookProperties - GetPropertyString() - 错误:=属性 "http://schemas.microsoft.com/mapi/string/{41FFBD02-4241-4EBD-A7B3-93DD2DF86CA9}/CaseGUID" 未知或找不到。
非常感谢提前
【问题讨论】:
-
异常处理不当是什么意思?