开发者

Dynamics Ax 2009, Exception Handling

开发者 https://www.devze.com 2023-02-04 22:40 出处:网络
In my x++ code I have the following void run() { try { startLengthyOperation(); this.readFile(); } catch (Exception::Deadlock)

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?


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.


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号