0

I am writing a wrapper for SSHnet dll from renci (https://sshnet.codeplex.com/), so I can fetch files from a sFTP server via Dynamics AX periodically.

When I catch errors in C# project for example in a try catch statement how can I parse the error message back to AX?

Options I thought of;

  1. Should I put the error message in a string variable and read the string in Dynamics AX?

  2. Write errors to the event log on the AOS / client?

CDspace
  • 2,639
  • 18
  • 30
  • 36
cel0x
  • 25
  • 5

1 Answers1

1

The easiest way to pass error to AX is a rethrow it in C#

catch (Exception ex) 
{
    // Do special cleanup, logging etc.
    throw;
}

and catch it in AX

catch (Exception::CLRError)
{
     ex = ClrInterop::getLastException();
     if (ex != null)
     {
        ex = ex.get_InnerException();
        if (ex != null)
        {
            error(ex.ToString());
        }
    }
}
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
Aliaksandr Maksimau
  • 2,251
  • 12
  • 21
  • Aliaksandr, Thank you very much! – cel0x Jan 29 '17 at 18:47
  • 1
    rethrow should be written as `throw;` See http://stackoverflow.com/questions/178456/what-is-the-proper-way-to-re-throw-an-exception-in-c and https://blogs.msdn.microsoft.com/jmstall/2007/02/15/throw-e-vs-throw/ – Matej Jan 30 '17 at 08:04