CLRInterop::getLastException Method
Retrieves the most recent CLR exception.
Syntax
client server public static CLRObject getLastException()
Run On
Called
Return Value
Type: CLRObject Class
The most recent exception of the Exception::ClrError type; otherwise, nullNothingnullptrunita null reference (Nothing in Visual Basic).
Remarks
If an attacker can control input to the getLastException method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission. Make sure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.
Examples
The following example tries to pass in a date that has an invalid format. The CLR exception that is thrown is converted to an X++ exception and then printed to the Infolog. Any nested exceptions are also printed to the Infolog.
static void Job2(Args _args)
{
CLRObject clrObj;
InteropPermission perm;
try
{
System.DateTime::Parse( "-1/-1/-1");
}
catch( Exception::CLRError )
{
perm = new InteropPermission(InteropKind::ClrInterop);
if (perm == null)
{
return;
}
perm.assert();
e = ClrInterop::getLastException();
CodeAccessPermission::revertAssert();
while( e )
{
info( e.get_Message() );
e = e.get_InnerException();
}
}
}