Catching errors

fufikkfufikk Member Posts: 104
Hi,

does anyone have anyidea how to catch an error, and get the error message in order to do something with it.

So far I got to the point, where I can check if an error occured, but without any idea how to get the message

what I do is:
somecodeUnit.Setparams(...) //to set some params for the Run function
result := somecodeUnit.RUN;

The result is true or false, depending wheater there wasn't or was an error. But how to get the message eg. "Sales Order could not be bla bla bla"

Comments

  • ara3nara3n Member Posts: 9,257
    You need to create another function in somecodeunit, for example get error.


    In your somecodeunit create a text 'texterror'. As you are validating the records


    texterror := 'validating No. field';
    validate("No.",'blaah');



    function geterror() as text {
    exit(texterror)
    }

    somecodeUnit.Setparams(...) //to set some params for the Run function
    result := somecodeUnit.RUN;

    if result = false then begin
    message(somecodeUnit.geterror);
    end;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
  • chen_wanchen_wan Member Posts: 34
    I think Navision do not have the (Try..Catch) or (OnError) error handling mechanism that other programming language can do.
  • DenSterDenSter Member Posts: 8,307
    Unfortunately, Navision does not have an error object, at least not one that you can access through C/AL.

    The only way to get any error information at all is to follow ara3n's advice. You have to know though that you have to declare the codeunit as a variable, and not call it by CODEUNIT.RUN(number). Also, the record variable that causes the error will be destroyed, so that's why you will have to store the field value before you validate.
Sign In or Register to comment.