Dynamics Ax 2009,异常处理
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 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.
有几件事:
- 据我所知,死锁会捕获数据库请求中的死锁。不确定 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.
它很容易是 Exception::CLRError ,在这种情况下,要查看问题,您可以选择重新抛出错误:
或 Exception::Internal ,然后类似:
或
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:or
Exception::Internal
, then something like:or
Exception::CodeAccessSecurity
or anything else - you'd need to show the code fromthis.readFile()
first. When you're debugging your code what line is causing the error?