Question

While trying to print a document in Navision, we get the error: Error message provided

Translation: This message is for C/AL programmers: The call to member ActivePrinter failed. Microsoft Word returned the following message: Printer error.

Error occurs in this line:

wrdApp.ActivePrinter := InteractLogEntry."Printer Name";

InteractLogEntry is a list, which is filled with every printer installed on the local system.

My Question: How can I get an handle this exception(Navision does not support exception handling through try-catch)

Can I use a if-else statement to solve this issue?

Was it helpful?

Solution

The best working try/catch replacement in classic client is to put the crashing code into the OnRun part of a seperate codeunit.

You can then call the code from another object (codeunit, form, report, etc) with an if-clause

IF NOT MyCrashyCodeunit.RUN THEN BEGIN
  // Errror handling here
END

OTHER TIPS

Since Dynamics NAV 2016 there is an alternative to calling a Codeunit and evaluating its return value.

Try Functions (See Property of function) were introduced and can be set to any function. When calling that function and(!) evaluating its boolean return value, errors are suppressed and therefor false is returned.

More information: https://docs.microsoft.com/en-us/dynamics-nav/handling-errors-by-using-try-functions

Important information:

Because changes made to the database by a try function are not rolled back, you should not include database write transactions within a try function. By default, the Microsoft Dynamics NAV Server configuration prevents you from doing this. If a try function contains a database write transaction, a runtime error occurs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top