Hot to catching ClrErrors in Dynamics AX

CLRError
// BP Deviation documented
static utcDatetime THK_UTCDatetime(name    _datetimeStr)
{
    utcDatetime         dt;
    InteropPermission   permission;
    name                datetimeStr = strlrTrim(_datetimeStr);
    System.Exception    ex;
    str                 ClrErrCatch;
;
    try
    {
        //Necessary if executed on the AOS
        permission = new InteropPermission(InteropKind::ClrInterop);
        permission.assert();
        if(permission && datetimeStr)
            // BP Deviation documented
            dt = CLRInterop::getAnyTypeForObject(System.DateTime::Parse(datetimeStr));
        else
            dt = dateTimeUtil::minValue();
    }

    catch (Exception::ClrError)
    {
        ex = ClrInterop::getLastException();
        if (ex != null)
        {
            ClrErrCatch  = ex.get_Message();
            ClrErrCatch += ex.get_StackTrace();
            ex = ex.get_InnerException();
            if (ex != null)
            {
                ClrErrCatch += ex.ToString();
            }
        }
        throw error(ClrErrCatch);
    }
    catch(exception::Error)
    {
        throw Error(strfmt("error %1 [%2]",funcName(),_datetimeStr));
    }
    ////Revert CAS back to normal
    CodeAccessPermission::revertAssert();
    return dt;
}
原文地址:https://www.cnblogs.com/Fandyx/p/2461472.html