Al: TryFunction not working or present?

Created on 11 Dec 2017  路  9Comments  路  Source: microsoft/AL

In the post https://github.com/Microsoft/AL/issues/270 I found a closed question about the TryFunction attribute.

Now the december release is available and I try the following code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    begin        
        // Test the TryFunction
        if not TryFunctionTest then 
          Message('TryFunction got the error')
        else
          Message('no Error');
    end;

    [TryFunction]
    local procedure TryFunctionTest(): Boolean;    
    var Stm: InStream;
        Txt: Text;
    begin
        // this should raise an error :)
        Stm.ReadText(Txt, 500);
        exit(True);
    end;
}

The result is not handled as expected:
grafik

What would be the right way, to use the concept of Try-Functions?

enhancement shipped

Most helpful comment

Tried to use it today to catch an error on the new Json types. Would be nice if this worked.

All 9 comments

It is on our backlog, but nothing has been worked on yet to replace it, given that its primary usage scenario was AL based .net exception handling.

My personal "primary usage scenario" is to run various TESTFIELDs on many (customized) document lines at runtime. Failed lines are marked in red for faster recognition, restoring to standard as soon as the user has fixed the line data. The code called by the TryFunction is also used when trying to release the document --> throw the actual error message.
In order to use repeatable code with and without error message, the TryFunction is very useful.

Tried to use it today to catch an error on the new Json types. Would be nice if this worked.

@StanislawStempin what is the current status?
Will we get TryFunctions or not?
If yes - when can we expect the TryFunctions?

We are currently working on it. TryFunctions will ship in the next major release of Business Central in Fall 2018.

TryFunctions shipped with Business Central Fall 2018. Please let us know if you encounter scenarios in which it doesn't behave as it used to.

Hi, am current on build 0.12.28462 and try to use the [TryFunction]. I have entrede the try procedure similar to Megel's example: [TryFunction] local procedure TryAsciiExportSalesHeader().
The issue happens when i call my procedure within a IF-THEN: if TryAsciiExportSalesHeader then begin. VSC markes it With "problems" With statement: Cannot implicitly convert type 'None' to 'Boolean' [AL0122]

@svwfr, this is not supported in NAV 2018

Now I have tried the [TryFunction] with the NAV2018 CU14 (build 27667), AL Language 0.13.82793 (Compiler version 0.13.1.17259) and supricly no compilation error as I explored with AL Language 0.12.28462. Is it supported for NAV2018 now?

Though, it does not work as intended as the orginial error is breaking the the code sequence and not my local code after call the TRY function. I did the same test within C/SIDE with success, as my local message was returned and not the orginial error-message.

The call I hoped to do a "try" for was:
Customer.CheckBlockedCustOnDoc(Customer,SalesHeader."Document Type",true,true);

Was this page helpful?
0 / 5 - 0 ratings