Trap Error

alex9
Member Posts: 97
Hi ,
I am trying to create a function( OR CodeUnit) that will catch Error in NAV and dump it in a Error Log Table. We want to use NAS, that will Post a Receipt for a Purchase order. Suppose that there was an error while posting, this Error should be inserted to a Error Log Table BUT not commit anything before then.. i.e - any other insert on any other table should fail.
e.g.
Suppose that you had
Table1.Insert();
Table2.Insert();
Table 3.Insert();
IF something=’’ THEN
IF NOT TrapError THEN
ERROR(‘ Something is blank’)
ELSE
BEGIN
WriteError(‘Somethig is blank’);
EXIT()
END;
I want WriteError to write to an Error Log but want the insert on Table 1,2 and 3 to fail. I believe that a commit on the WriteError Function will also insert on T1,T2, and T3 which is not desired.. Any thoughts? Or automation out there? I.e I don’t want to use a TXT File.
I am trying to create a function( OR CodeUnit) that will catch Error in NAV and dump it in a Error Log Table. We want to use NAS, that will Post a Receipt for a Purchase order. Suppose that there was an error while posting, this Error should be inserted to a Error Log Table BUT not commit anything before then.. i.e - any other insert on any other table should fail.
e.g.
Suppose that you had
Table1.Insert();
Table2.Insert();
Table 3.Insert();
IF something=’’ THEN
IF NOT TrapError THEN
ERROR(‘ Something is blank’)
ELSE
BEGIN
WriteError(‘Somethig is blank’);
EXIT()
END;
I want WriteError to write to an Error Log but want the insert on Table 1,2 and 3 to fail. I believe that a commit on the WriteError Function will also insert on T1,T2, and T3 which is not desired.. Any thoughts? Or automation out there? I.e I don’t want to use a TXT File.
0
Comments
-
You need a new codeunit that will call your codeunit
It will call your codeunit in the following way.
Onrun
If not Codeunit.run() then begin
WriteLog(getlastErrortext);
clearlastErrorText;
commit;
end;0 -
alex9 wrote:Hi ,
I am trying to create a function( OR CodeUnit) that will catch Error in NAV and dump it in a Error Log Table. We want to use NAS, that will Post a Receipt for a Purchase order. Suppose that there was an error while posting, this Error should be inserted to a Error Log Table BUT not commit anything before then.. i.e - any other insert on any other table should fail.
e.g.
Suppose that you had
Table1.Insert();
Table2.Insert();
Table 3.Insert();
IF something=’’ THEN
IF NOT TrapError THEN
ERROR(‘ Something is blank’)
ELSE
BEGIN
WriteError(‘Somethig is blank’);
EXIT()
END;
I want WriteError to write to an Error Log but want the insert on Table 1,2 and 3 to fail. I believe that a commit on the WriteError Function will also insert on T1,T2, and T3 which is not desired.. Any thoughts? Or automation out there? I.e I don’t want to use a TXT File.
I will NEVER go the way when you need to modify all calls of ERROR function etc. Because there are validate errors testfield errors etc. Ara3n's solution is much better, because it is generic and you do not need to modify existing code. It is working on NAV 5.0 and higher. If you are using older NAV, you can do technical upgrade or you can use another way, using NTimer automation which have OnError event to catch the error and write it. Than you only need to call the function for posting the document in OnTimer event for each document...0 -
Thanks everyone for the reply.. I was wondering how you would “getLastErrorText” if the error message originated for the Codeunit.RUN(xx) and xx has just error out. Is the intention to modify CU xx also?
If not Codeunit.run() then begin WriteLog(getlastErrortext); clearlastErrorText; commit; end;
0 -
this is a new function added in 5.x version executables. The client keeps track of the error and you can retrieve it.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions