# System.GetLastErrorObject() Method
> Version: _Available or changed with runtime version 2.0._
Gets the last System.Exception object that occurred.
> NOTE
> This method is supported only in Business Central on-premises.
## Syntax
```al
DotNet :=   System.GetLastErrorObject()
```
> NOTE
> This method can be invoked without specifying the data type name.
## Return Value
DotNet
Type: ../dotnet/dotnet-data-type
## Remarks
You use this method to retrieve and handle the last exception that occurred in the application. The System.Exception object exposes several members that enable you to get detailed information about the exception, such Exception.InnerException and Exception.Message.
## Example
This example uses the GetLastErrorObject method to get an exception object that occurs. In this example, the Microsoft .NET Framework objects are executed by MyCodeunit. The AL code uses the InnerException property of the System.Exception object to identify whether the inner exception has the type WebException and returns an exception message accordingly.
```al
var
    MyCodeunit: Codeunit MyCodeunit;
    Exception: DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebException";
    WebException: DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Exception";
begin
    if not MyCodeunit.Run then begin
        Exception := GetLastErrorObject;

        if not Exception.InnerException.GetType.Equals(WebException.GetType) then
            Error(Exception.Message);

        WebException := Exception.InnerException;
        Error(WebException.Message);
    end;
end;
```
## Related information
system-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-getlasterrorobject-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-getlasterrorobject-method/
