Dynamics Ax 2009,异常处理

发布于 2024-10-12 05:23:43 字数 500 浏览 5 评论 0原文

在我的 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();
}

我正在完成最后的任务(之前,我没有收到有关异常的消息)。但我想知道到底发生了什么并导致了异常。我怎样才能知道异常是什么?

In my x++ code I have the following

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();
}

I am hitting the final catch (prior, I was getting no message about exceptions). But I want to know what is REALLY happening and causing the exception. How can I find out what the exception is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静若繁花 2024-10-19 05:23:43

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

You could add stackTrace to the info log and add an info message when you get to the last catch. That would show you exactly what the code was doing at the time it reached the catch.

离不开的别离 2024-10-19 05:23:43

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

不确定 readFile 的作用。当我想到 AsciiIO 和 TextIO 时,它们通常会读取某些内容,因此我只能假设您是在 readFile 中执行此操作。
我倾向于做这些检查:
检查文件路径是否不是空的。
使用 FileIOPermission 断言读或写。
使用文件路径作为输入创建 AsciiIO 或 TextIO 对象的实例。
检查对象是否有效,如果无效则提醒用户。

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

A couple of things:
- Deadlock as far as I know catches deadlocks in database requests. Not sure what readFile is doing but it doesn't sound like its querying the database.
- The methods startLengthyOperation (and end) are there to make the mouse cursor look like the hourglass duing the lengty operation.

Not sure what the readFile does. When I think of AsciiIO and TextIO they normally read into something, so I can only assume you're doing that within readFile.
I tend to do these checks:
Check if filepath is something other than empty.
Use FileIOPermission to assert read or write.
Create the instance of the AsciiIO or TextIO object with the filepath as input.
Check if the object is valid, and if not alert the user.

Hope this helps, and if so, please vote.

遗弃M 2024-10-19 05:23:43

它很容易是 Exception::CLRError ,在这种情况下,要查看问题,您可以选择重新抛出错误:

throw error(AifUtil::getClrErrorMessage());

或 Exception::Internal ,然后类似:

System.Exception e = CLRInterop::getLastException();
if (e)
    throw error(e.ToString());

Exception::CodeAccessSecurity 或其他任何内容 - 您需要首先显示 this.readFile() 中的代码。当您调试代码时,哪一行导致了错误?

It could easily be Exception::CLRError, in which case to see the problem you could choose to re-throw the error:

throw error(AifUtil::getClrErrorMessage());

or Exception::Internal, then something like:

System.Exception e = CLRInterop::getLastException();
if (e)
    throw error(e.ToString());

or Exception::CodeAccessSecurity or anything else - you'd need to show the code from this.readFile() first. When you're debugging your code what line is causing the error?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文