Exception Handling in Navision

I have made a form that can import any table with any no. of fields specified, from an excel file. This is done using excel automation. The problem is that when a file has some improper field type (ex: for an imteger column, it has some text), then an error occurs telling that this problem has occurred and the whole operation stops. That is ok because it must throw error to tell that the file has problem. But after the error, the Excel Automation server stays open because the code for closing is not executed. Then the user needs to close it manually from task manager.

Is there any way to handle this kind of exception? In C++ or Java or in Axapta also, this can be stopped by Try – Catch Blocks, is there anything possible for navision?

Sorry but here isn’t. You must validate input to avoid generate errors.

The way I would do it is import every value as text and then use evaluate to convert it to integer or date or whatever the date type is.

That function returns an error message if not possible so that is your way to catch errors.

I have done the same as you have. It helps me very much except for some cases where the table has some validation properties and the validation throws errors. In these cases the system suddenly stops without clearing the Excel. Validate trigger also does not have any output type so that i can use this in any IF ELSE block. Guess this is the only way. Anyway, Thank you BOTH for your helps and to make me sure that there is no other way. :slight_smile:

Hi Rob,

You don’t mention wich version You’re on.

If You’re on 5.0, You could look into GETLATESTERRORTEXT & CLEARLATESTERROR (found in the C/AL-symbol menu, under SYSTEM - Error-handling).
Maybe these can help You achieve what You want.
If they can do the trick for You, and You’re not on 5.0, You can consider a technical upgrade, just to have that functionality available.

Try to make the validations in a codeunit; if a codeunit hits an error it aborts and return a FALSE to sender.

Call the codeunit like this:

IF NOT CODEUNIT.RUN(CODEUNIT::MyCodeunit, MyRecordToValidate) THEN
MESSAGE(‘An error occurred.’);

It is not possible to catch the specific error unless you make some coding. Or if you work in NAV 5, the new GETLASTERRORTEXT may be used.

Thank you all! The two techniques last were able to cure the problem :slight_smile:

Thank you again for everything!

Hi Rob,

The RIM toolset does exactly what you are doing here (although the hangiong Excel task is a problem. You should download this and have a look. Also the Data Migration toolset addresses this issue/