2017-01-27 53 views
0

我正在爲renci(https://sshnet.codeplex.com/)編寫SSHnet dll的包裝,因此我可以定期通過Dynamics AX從sFTP服務器獲取文件。AX 2012 R3 Visual Studio項目C#解析錯誤

當我在例如try catch語句中找到C#項目錯誤時,我該如何將錯誤消息解析回AX?

我想到的選項;

  1. 我應該把錯誤消息在一個字符串變量並讀取Dynamics AX中的string

  2. 錯誤到AOS /客戶端上的事件日誌?

回答

1

傳遞錯誤AX最簡單的方法是重新拋出它在C#

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

,並抓住它在AX

catch (Exception::CLRError) 
{ 
    ex = ClrInterop::getLastException(); 
    if (ex != null) 
    { 
     ex = ex.get_InnerException(); 
     if (ex != null) 
     { 
      error(ex.ToString()); 
     } 
    } 
} 
+0

亞歷山大·, 非常感謝您! – cel0x

+1

rethrow應該寫成'throw;'請參閱http://stackoverflow.com/questions/178456/what-is-the-proper-way-to-re-th-row-an-exception-in-c和https:/ /blogs.msdn.microsoft.com/jmstall/2007/02/15/throw-e-vs-throw/ – Matej