AX 2012 R3 Visual Studio 项目 C# 分析错误



我正在为renci(https://sshnet.codeplex.com/)的SSHnet dll编写包装器,因此我可以通过Dynamics AX定期从sFTP服务器获取文件。

当我在项目中捕获错误时C#例如在 try catch 语句中,如何将错误消息解析回 AX?

我想到的选项;

  1. 我是否应该将错误消息放在字符串变量中并在动态AX中读取string

  2. 错误写入 AOS/客户端上的事件日志?

将错误传递给 AX 的最简单方法是在 C# 中重新抛出错误

catch (Exception ex) 
{
    // Do special cleanup, logging etc.
    throw;
}

并在AX中捕获它

catch (Exception::CLRError)
{
     ex = ClrInterop::getLastException();
     if (ex != null)
     {
        ex = ex.get_InnerException();
        if (ex != null)
        {
            error(ex.ToString());
        }
    }
}

最新更新