# TryFunction attribute
> Version: _Available or changed with runtime version 1.0._
Specifies the method to be a try method, which can be used to catch and handle errors and exceptions that occur when code is run.
## Applies to
 Method
## Syntax
> Version: _Available or changed with runtime version 2.0._
```al
[TryFunction]
procedure TryFunction()
```
## Remarks
> NOTE
> In test and upgrade codeunits, this property only applies to normal methods as specified by the Normal Attribute \(Test Codeunits\)<devenv-normal-attribute> or ../devenv-methodtype-property-upgrade-codeunits.
Try methods in AL enable you to handle errors that occur in the application during code execution. For example, with try methods, you can provide more user-friendly error messages to the end user than those thrown by the system. You can use try methods to catch errors/exceptions that are thrown by Business Central or exceptions that are thrown during .NET Framework interoperability operations.
See ../devenv-handling-errors-using-try-methods.
## Example
The IsSecureHttpUrl method raises an error when a URL doesn't start with `https://`. The TryFunction attribute lets the OnRun trigger detect and handle the error without stopping execution.
```al
codeunit 50100 TryFunctionExample
{
    trigger OnRun()
    begin
        if not IsSecureHttpUrl('http://www.contoso.com') then
            Message('The URL is not secure.');
    end;

    [TryFunction]
    local procedure IsSecureHttpUrl(Url: Text)
    begin
        if CopyStr(Url, 1, 8) <> 'https://' then
            Error(NonSecureUrlErr);
    end;

    var
        NonSecureUrlErr: Label 'The URL must use HTTPS.';
}
```
## Related information
AL Method Reference<../methods-auto/library>
../devenv-essential-al-methods
devenv-method-attributes
../devenv-handling-errors-using-try-methods
../properties/devenv-properties

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/attributes/devenv-tryfunction-attribute, 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/attributes/devenv-tryfunction-attribute/
