Exception Handling in custom control in .NET

wakestar
wakestar Member Posts: 207
Hello experts ;)

I wrote my own custom control (WinForm) in .net using c#. It exposes several methods and events to Navision through COM-Automation.

There are situations where exceptions (critical and noncritical) can be throwed in the .Net- Control. And then ERRORs may also occur in Navision.

Questions:

- How do you manage exceptions throwed in .NET? (I'm not asking how "try catch finally" works in .NET).
What I did is: catch non-critical exception in .NET and pass the Exception-Message to Navision through an event and display it in Navision with MESSAGE(ExceptionMessage).

- How do you manage Navision ERRORs throwed by Navision between some events fired by the .net control?
(The CLR throws Navision ERRORs as COMExceptions... unfortunately I cannot recognize that Navision throwed them:$exception.TargeSite.base.Name =ForwardCallToInvokeMember)

Thanks for your input :)

Comments

  • SteveO
    SteveO Member Posts: 164
    Hi Wakestar,

    I tend to do exactly what you have described wrt passing errors back to Navision and then show the error via Navision. :)

    When catching Navision errors I just catch the COMExceptions because they must have been thrown by Navision (unless the instance of your COM control is shared across multiple applications).
    This isn't a signature, I type this at the bottom of every message
  • wakestar
    wakestar Member Posts: 207
    Hi SteveO

    I'm using the Outlook PIA (Primary Interop Assembly) within my control which may throw COMExceptions. But then the $exception.TargeSite.base.Modul is '{Outlook.dll}'.
    I think I will send COMExceptions only from this Modul back to Navision.
    Otherwise I'm getting the same Error-Message twice in Navision ...first time with ERROR('navision is not happy') and then as a COMException in the CLR.
    What do you think?
  • SteveO
    SteveO Member Posts: 164
    I would probably ignore exceptions where the Module is not Outlook.dll (because then it is most likely Navision) and then do whatever action is necessary only with the Outlook.dll exceptions.
    Can't really think of any alternatives right now.
    This isn't a signature, I type this at the bottom of every message