Is there a way to catch an sql insert error in nav code from outside the function?
a little example (just to make things clear):
i have 2 tables
both have this setup
1 code code 10
2 description text 30
All i do is copy the data over from one table to the other like this:
Fct_MoveData()
LRec_1.RESET;
IF LRec_1.FINDSET(FALSE,FALSE) THEN BEGIN
REPEAT
LRec_2.RESET;
LRec_2.TRANSFERFIELDS(LRec_1);
LRec_2.INSERT(TRUE);
UNTIL LRec_1.NEXT = 0;
END;
However when i run the codeunit the second time i get this error
Microsoft Dynamics NAV Classic
Tabel testtable2 is reeds aanwezig.
Velden en waarden:
code='01'
OK
Which is expected as it should occur. I know i can write an "if" around it to catch the error. But i dont want to go around writing if's all over the database to then throw my own error that i can log with the getlasterrortext function.
So i'd like to know if there is a way to catch this without having to modify all over the place, as mentioned before the example above is merely for posting an example.
Comments
MyCU5000
onRun
Fct_MoveData();
Then you create another CU and call it
if MyCU5000.run then begin
message('success');
end else begin
logtheerror(getlasterrortext);
clearlasterrortext;
end;
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
for example:
2 codeunits:
60000:
Codeunit 60001
Do you have any code on sql trigger?
I have seen this before where an insert error would stop the execution of the calling CU.
I suggest to report it to MS if you can replicate it in Cronus. probably newest executable.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
no code on sql trigger.
I'm not getting the message. It stops at the insert when i enable the debugger.
Will have a look in cronus and come back when i have the results
Thanks so far already