How To Execute The Code After Error Message

lakshmanlakshman Member Posts: 44
DEAR ALL,
Please Suggest me how to execute the code ofter error message
without stop the execution.


Thanks & Regards :
lakshman
Best Regards,
Lakshman Routu
http://lakshman-routu.blogspot.in/

Comments

  • garakgarak Member Posts: 3,263
    ??? Do you know how a error worked :?:
    With an error, the DBMS makes a rollback of the current transaction, for example your posting. Why you will stop this and risk inconsistent transactions :?: ](*,) [-X
    Do you make it right, it works too!
  • krzychub83krzychub83 Member Posts: 120
    You can use CodeUnit's RUN funtion.

    IF CodeUnit.RUN() THEN
    MESSAGE('No Error in this')
    ELSE
    MESSAGE('There was an error');

    Of course You lose the rest of CodeUnit.RUN code, but still You are able to handle an error appearance. I don't remember any other way of not stopping Your code. Maybe this will help You.
  • bbrownbbrown Member Posts: 3,268
    krzychub83 wrote:
    You can use CodeUnit's RUN funtion.

    IF CodeUnit.RUN() THEN
    MESSAGE('No Error in this')
    ELSE
    MESSAGE('There was an error');

    Of course You lose the rest of CodeUnit.RUN code, but still You are able to handle an error appearance. I don't remember any other way of not stopping Your code. Maybe this will help You.

    If you take this approach you must also handle the rollback. NAV will see this has a successful transaction and commit any changes.
    There are no bugs - only undocumented features.
  • kinekine Member Posts: 12,562
    bbrown wrote:
    krzychub83 wrote:
    You can use CodeUnit's RUN funtion.

    IF CodeUnit.RUN() THEN
    MESSAGE('No Error in this')
    ELSE
    MESSAGE('There was an error');

    Of course You lose the rest of CodeUnit.RUN code, but still You are able to handle an error appearance. I don't remember any other way of not stopping Your code. Maybe this will help You.

    If you take this approach you must also handle the rollback. NAV will see this has a successful transaction and commit any changes.

    But only for what was done before the Codeunit.RUN...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jlandeenjlandeen Member Posts: 524
    Anothing thing on error handling is that you can actually determine the last error - this is especially useful when working with NAS and there is no user interface but you want to be able to log or otherwise notify an admin of the failure condition.

    In version 5.0 of Navision they've implemented GETLASTERRORTEXT and CLEARLASTERROR functions. These can be used in conjuction with the programming patter described here using the IF CODEUNIT.RUN() to return the actual error that would be propagated to the users screen.

    This is vastly superior to just logging an error has occurred or trying to guess what could have caused the error.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • lakshmanlakshman Member Posts: 44
    Dear all,

    Actually my requirement is i have emp table with Eno,Ename,salary,post(boolean).i write two codeunits like below


    codeunit1


    IF Emp1.FIND('-') THEN
    REPEAT
    IF Emp1.Post=FALSE THEN
    IF EmpCu.check(Emp1) THEN
    Emp1.Post:=TRUE;
    Emp1.MODIFY;
    UNTIL Emp1.NEXT=0;

    codeunit2

    empcu.check(rec);
    if emp.sallary=0 then
    emp.textfield(salary);
    whenever i run 1 st codeunit then it checks post false then call 2nd codeunit .in second code unit checks salary is null then it shows error stop the execution else goes to step.but i need process all records except employee whose salary is 0.
    i.e i have 50 employee if 10 th employee's salary=0 then show error and stop the execution but i need process the next employee records also execept 10th employee
    Best Regards,
    Lakshman Routu
    http://lakshman-routu.blogspot.in/
  • kinekine Member Posts: 12,562
    Why just do not calc the salary and skip the records with salary 0? Is the calculation of the salary so complex step? Or it is just some field? This way of "catching" error is good when you expect many errors you cannot handle before calling the needed function (like posting function) through code and you can do all the steps as separate transaction.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.