Exception handling Dynamics Ax 2009,异常处理

Exception handling Dynamics Ax 2009,异常处理,exception-handling,axapta,x++,dynamics-ax-2009,Exception Handling,Axapta,X++,Dynamics Ax 2009,在我的x++代码中,我有以下内容 void run() { try { startLengthyOperation(); this.readFile(); } catch (Exception::Deadlock) { retry; } catch (Exception::Error) { error(strfmt("An error occured while

在我的x++代码中,我有以下内容

void run() {
    try
    {
        startLengthyOperation();
        this.readFile();    
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
    catch (Exception::Error)
    {
        error(strfmt("An error occured while trying to read the file %1", filename));
    }
    catch
    {
        error("An unkown error has occured");
    }

    endLengthyOperation();
}
我正在完成最后一个任务(之前,我没有收到关于异常的消息)。但我想知道到底发生了什么,以及导致异常的原因。我怎样才能知道例外情况是什么?

有几件事: -据我所知,死锁捕获数据库请求中的死锁。不确定readFile在做什么,但听起来不像是在查询数据库。 -有一些方法可以使鼠标光标在执行长操作时看起来像沙漏

不确定readFile做什么。当我想到AsciiIO和TextIO时,它们通常会读入一些内容,所以我只能假设你是在readFile中这样做的。 我倾向于做这些检查: 检查文件路径是否不是空的。 使用FileIOPermission断言读或写。 使用文件路径作为输入创建AsciiIO或TextIO对象的实例。 检查对象是否有效,如果无效,则通知用户


希望这有帮助,如果有,请投票。

很容易出现异常::clerror,在这种情况下,要看到问题,您可以选择重新抛出错误:

throw error(AifUtil::getClrErrorMessage());
或者
Exception::Internal
,然后类似于:

System.Exception e = CLRInterop::getLastException();
if (e)
    throw error(e.ToString());
或者
Exception::CodeAccessSecurity
或其他任何内容-您需要首先显示
this.readFile()
中的代码。调试代码时,哪一行导致了错误?

您可以在最后一次捕获时添加一条信息消息。这将准确地显示代码到达捕获点时正在执行的操作