Options

DotNet Interop and Exception Handling

wakestarwakestar Member Posts: 207
edited 2015-01-29 in NAV Three Tier
Hi all

Since we are not able to catch .NET Exceptions in NAV.... I wonder what the preferred workaround is?

At the moment I can think of the following workarounds:

- write a generic .net assembly which uses reflection to call the classes and methods and handles the exceptions in a generic way
- write c# scripts on the fly and use an external engine like CS-Script
- write c# scripts on the fly and use .net internal classes with DotNet Interop to run the script (not sure if that works)

Any other ideas or recommendations?
How do you handle it?

Comments

  • Options
    ftorneroftornero Member Posts: 522
    Have you try the ASSERTERROR, GETLASTERRORTEXT combination ?

    Regards.
  • Options
    wakestarwakestar Member Posts: 207
    No, I haven't tried that. I guess it's good for catching the error without wasting an "IF NOT Codeunit.RUN()"?
    In case you need the actual exception message.. you're stuck right?

    As an example: WebRequest.GetResponse() throws an WebException and you want to know wheter the http status code is 500, 404 or 200
    https://msdn.microsoft.com/de-de/library/system.net.httpwebrequest.getresponse%28v=vs.110%29.aspx

    I'm looking for a solution without the installation and deployment hassle.
  • Options
    ftorneroftornero Member Posts: 522
    To get the actual exception message is what the GETLASTERRORTEXT is for.

    Regards
  • Options
    vytjakvytjak Member Posts: 36
    You can read through Vjeko's thoughts on the topic, and see if there's anything that you can use in your case:
    http://vjeko.com/tags/exception-handling
    Vytenis Jakas
    B3 Technologies - Making Technology Serve the People
  • Options
    wakestarwakestar Member Posts: 207
    hi there

    thanks, yes I saw vjeko's blog

    My original question was: which of the different solutions (read:workraounds) do you use and why?
Sign In or Register to comment.