Hi,
I'm having a weird problem when trying to catch a CRL Exception in AX 2009. I haven't had this problem before with other CLR operations, but when using the System.IO.StreamWriter .NET class and an exception is thrown I'm not able to handle it in a catch statement.
It would be great to have some insight about this.
The following is my code:
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
if(WinApi::fileExists(invoiceFilePath))
WinApi::deleteFile(invoiceFilePath);
sw = new System.IO.StreamWriter(invoiceFilePath); //This is where it crashes and does not fall into the CLRException
//Write in file
….LOGIC HERE (Too long to post it) ….
sw.Flush();
sw.Close();
sw.Dispose();
CodeAccessPermission::revertAssert();
break;
}
}
catch
{
this.eInvoiceProcessTextWriteError();
}
catch(Exception::Internal)
{
this.eInvoiceProcessTextWriteError();
exc = CLRInterop::getLastException();
if( exc )
{
clrExcMessage = exc.get_Message();
// BP Deviation Documented
strError = CLRInterop::getAnyTypeForObject( clrExcMessage );
throw error(strError);
}
}
catch(Exception::CLRError)
{
this.eInvoiceProcessTextWriteError();
exc = CLRInterop::getLastException();
if( exc )
{
clrExcMessage = exc.get_Message();
// BP Deviation Documented
strError = CLRInterop::getAnyTypeForObject( clrExcMessage );
innerExc = exc.get_InnerException();
while(innerExc != null)
{
clrExcMessage = innerExc.get_Message();
// BP Deviation Documented
strError = strError + '\n' + CLRInterop::getAnyTypeForObject( clrExcMessage );
innerExc = innerExc.get_InnerException();
}
throw error(strError);
}
}
catch(Exception::Error)
{
this.eInvoiceProcessTextWriteError();
}
Any help will be appreciated!
*This post is locked for comments