Partager via


CLRInterop.getLastException Method

Definition

Retrieves the most recent CLR exception.

public:
 static System::Object ^ getLastException();
public static object getLastException ();
static member getLastException : unit -> obj
Public Shared Function getLastException () As Object

Returns

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.

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(); 
        } 
    } 
}

Applies to