Wednesday, April 21, 2010

Getting CLR exception message

An exception that appears in AX if something went wrong in the managed code you are running doesn't contain much information about what have happened. For example, it can be something like: Object 'CLRObject' could not be created. But, there is a trick which helps to get more meaningful message, actually the one that was thrown in CLR - AifUtil::getClrErrorMessage().

Example:
ServiceNamespace.MyService service;

try
{
    service = new ServiceNamespace.MyService();
}
catch
{
    throw error(AifUtil::getClrErrorMessage());
}

Gives the following information:

7 comments:

  1. Nice. So much quicker that the loads of code I am using for that now. Does this work even if the AIF configuration/license is off?

    ReplyDelete
  2. It should, however I haven't tried.

    ReplyDelete