Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Apologies for the late reply - busy week!</p> <blockquote> <p>The whole idea of exception catching is not to "swallow" them and display the error message, but to recover, if possible from the situation, as well as to cleanup resources.</p> </blockquote> <p>Yup, that's the idea but in practice it doesn't always work out that cleanly. The code in question here is essentially a middleman and often can't know if an error will occur and if one happens it can't know what the user was actually trying to do and thus automagically recover.</p> <blockquote> <p>Does it happen always?</p> </blockquote> <p>Yes, if it is an unexpected exception and it always appears as a .NET one originating within the C#/.NET code</p> <blockquote> <p>create a simple method, which just throws an exception( throw new ApplicationException();), and see if you still have the problem?</p> </blockquote> <p>No, throwing our own exceptions works fine every time. It's only if the runtime itself generates the exception that we get hard crashes.</p> <blockquote> <p>you are not releasing the MS Excel COM objects you are implicitly creating when an exception is thrown</p> </blockquote> <p>This sounds plausible. A VBA layer passes data from Excel over COM and into .NET, so it could well be doing something funky with resource ownership.</p> <blockquote> <p>If you want centalized logging, look at Application.ThreadException (for WinForms app) and AppDomain.CurrentDomain.UnhandledException instead.</p> </blockquote> <p>I didn't look into the former, but the latter would never get called. One of my first attempts was to catch it at the AppDomain level assuming that, for whatever reason, a delegate-based exception was slipping through the net.</p> <blockquote> <p>you may want to call Marshal.ReleaseComObject()</p> </blockquote> <p>Interesting, I wasn't aware of that function. We've mostly ignored any explicit COM code and gone with the bare minimum and hope (!) that the .NET CLR does its magic... </p> <p>I've worked around it now by removing the delegates and everything seems happy. Just have to remember to be careful (or outright avoid) delegates and exceptions in future Office+VBA+COM+CLR code :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload