Catching Errors In Navision -- Useful even for the Experts

girish.joshi
Member Posts: 407
We all know (and if you don't search the forum) that the only way to catch errors in Navision is the
structure. We also know that you can programatically call codeunits with the this structure
However, its less known that when using the latter structure anywhere in the cal stack, it will cause errors from the previous structure to NOT be caught.
To put it another way, if you use the if codeunit.run() structure anywhere in the call stack, you can't catch any errors. Very important when writing code that use the Job Scheduler.
If codeunitA.RUN then
structure. We also know that you can programatically call codeunits with the this structure
Codeunit.run( Codeunit's Object Number )
However, its less known that when using the latter structure anywhere in the cal stack, it will cause errors from the previous structure to NOT be caught.
To put it another way, if you use the if codeunit.run() structure anywhere in the call stack, you can't catch any errors. Very important when writing code that use the Job Scheduler.
0
Comments
-
We all know (and if you don't search the forum) that the only way to catch errors in Navision is the
Code:
If codeunitA.RUN then
structure.
It is not true that this is the only way to catch errors with codeunits. There is really no difference between calling theRUN()
method of a codeunit variable, or just writingCODEUNIT.RUN(Number)
If you call the latter example the same way using the IF structure, you can catch the errors in the very same way.
There is only one advantage to using a codeunit variable: you can initialize the codeunit by calling user defined functions that set global variables, and you can obtain the result of the transaction by calling user defined functions that return status, or whatever that is stored in global vatriables.
The difference between calling the RUN procedure (any way) with the IF structure, is that Navision handles the erros by aborting - and rolling back - the transaction when you don't use the IF structure. If this is not wat you want, or you need custom error handling, you can use the IF structure. It just works like the GET from the RECORD variable type.0 -
We've also used an sheduler working on NAS.
But i needed the information about the error.
I needed the whole error message.
With other words, the message that is display if there where an userinterface. But nas doesnt have Guid.
So i've changed my code to folloing:
loop through Seduling setup recordsif CU.Run(Number in ShedulingRecord) ... .... DeleteExistingErrorlogs (Table in Navision, include the ShedulingRecID, Date, an Flag if send) end else exist an Errorlog in the ErrorLogTable for this CUJob on this day? No: Create an errorlog in the ErrorLogTable CU.Run() <- to get the whole Errormessage <- NAS write it into System.Eventlog yes is the message not send? Get the Errorlog from System.EventLog Send the Message in System.Eventlog per Mal to me set the Errorlog in ErrorLogTable as send end end;
With this, i can see, why the job is not running.Do you make it right, it works too!0 -
Hello,
I havn't tried that yet, but I sure will sometime in the future. I've been writing custom error handling code that sets an error message to be retrieved by a custom function. It sure is a lot of work. You end up with more error catching code than anything else! Your solution will save me a lot of time!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