Wednesday, February 15, 2017

Catch any type exception

For debugging different types of CLR exception, it took me ages to find the following code, but this helps in finding what kind of exception could be giving the problem (taken from http://sebastienayotte.com/dev/catching-exceptions-microsoft-dynamics-ax-2012/ and saved for future use. All credit goes to the original dev)

Catching Any Type of Exceptions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
System.Exception exception;
 
try
{
    System.Int16::Parse('abcd');
 
    throw Exception::Error;
}
catch
{
    error('Caught an exception');
 
    error(con2Str(xSession::xppCallStack()));
 
    exception = CLRInterop::getLastException();
 
    while (exception)
    {
        error(CLRInterop::getAnyTypeForObject(exception.ToString()));
 
        exception = exception.get_InnerException();
    }
}

No comments:

Post a Comment