最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

AX 2012:处理 CLR 异常 / AX 2012: Handling CLR exceptions

网络文摘 William 566浏览 0评论

Purpose:

The purpose of this post is to demonstrate how can we effectively handle CLR exceptions.

Application:

Dynamics AX 2012

Business requirement:

To report CLR inner exception.

Solution:

Please find the code below to get the inner CLR exception.

Code

private void getFiles()
{
    System.String[] files;
    System.Collections.IEnumerator enumerator;
	str file;
	;

    try
    {
        fileSet = new Set(Types::Container);
        files = System.IO.Directory::GetFiles(filePath, '*.csv');

        enumerator = files.GetEnumerator();

        while (enumerator.MoveNext())
        {
            file = enumerator.get_Current();
            fileSet.add([file]);
        }
    }
    catch (Exception::Internal)
    {
        this.processCLRErrorException();
    }
    catch (Exception::CLRError)
    {
        this.processCLRErrorException();
    }
}
private void processCLRErrorException(boolean _throw = true)
{
    CLRObject exc;
    CLRObject innerExc;
    CLRObject clrExcMessage;
	str strError;
    ;

    exc = CLRInterop::getLastException();

    if (exc)
    {
        innerExc 	  = exc.get_InnerException();
		clrExcMessage = exc.get_Message();
        
        while (innerExc != null)
        {
            innerExc      = innerExc.get_InnerException();
			clrExcMessage = innerExc.get_Message();
        }

        strError = CLRInterop::getAnyTypeForObject(clrExcMessage);

        error(strError);

        if (_throw)
        {
            throw error("Update has been cancelled");
        }
    }
}
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址