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
DotNet := System.GetLastErrorObject()
Note
This method can be invoked without specifying the data type name.
Return Value
DotNet
Type: DotNet
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.
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;
See Also
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈