Handling the InternalException or an application crash from the add-in.

Handling the InternalException or an application crash from the add-in.

Anonymous
Not applicable
568 Views
1 Reply
Message 1 of 2

Handling the InternalException or an application crash from the add-in.

Anonymous
Not applicable

Hello,

 

I have an add-in that monitors open document elements, read-only, figuring how many sheets, links, families etc., using a bunch of IUpdaters, and further sends them off to an external server for some usage analysis. I would like to be able to detect a crash in the application, before the "Unrecoverable error has occurred" dialog, so I can flag my monitoring data with the last result as "crashed", which would help me with the analysis.

 

I have to say that I am simulating a crash by running two FilteredElementCollectors in a BackgroundWorker, I know, blasphemy. This causes an InternalException with the error/submit report dialog.

 

What I've tried so far:

- As per The Building Coder: http://thebuildingcoder.typepad.com/blog/2013/10/handle-your-own-exceptions-and-edit-slab-boundaries... subscribing to the App.Domain.CurrentDomain.UnhandledException doesn't work for me and the handler doesn't get called.

- FailureProcessor and FailurePreprocessor don't work with the InternalException, perhaps I need a better crashing sample file.

- A watchdog application (wrapper) that calls the Revit executable and looks at the exit code/reads the journal file, this works, but would be better to have a self-contained solution.

 

What I'm trying to achieve:

- Before Revit throws and exists, I collect some bits of info, timestamps (no longer need RevitAPI), and make a POST to a webapi with this info.

 

Is this possible?

 

Thank you,

Alex

0 Likes
569 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
AppDomain.CurrentDomain.FirstChanceException += CurrentDomainOnFirstChanceException;

public static void CurrentDomainOnFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
{
if (e.Exception is InternalException) {
MessageBox.Show($"{e.Exception.Source}{e.Exception.StackTrace}\n {e.Exception.Message}");
}
}

This seems to be doing the job actually, even though it gets fired on every single exception before the application gets the chance to handle it internally. The add-in remains loaded and I can get some information out and post some data to my server. I would love to hear other ideas though!

0 Likes