I am developing an Optical character recognition software using WPF. I have third party hardware that does this ocr thing. I also have the device driver provided from the manufacture. I have referenced the device driver's dll in my project and I call one of its method to convert image to text. For example, I can put my passport on the device and I get array of information from the passport. The function works as expected but sometimes the application closes without any exception thrown. This is due to the device driver dll as seen from the window event logs. There is an unhandled exception in the dll that closes the application suddenly.
I want my WPF application to run no matter the whatever be the exception thrown by the dll file.
I have globally handled error in the app.cs file
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
var dialogContent = "Exception Message:" + "\n" + e.Exception.Message +
"\n" + "Stack Trace:" + "\n" + e.Exception.StackTrace;
MessageBox.Show(dialogContent);
e.Handled = true;
}
I have also added tried to add these attributes on my method.
[SecurityCritical]
[HandleProcessCorruptedStateExceptions]
public void ConvertImagetoText()
{
try
{
//do something from the dll file.
}
catch
{
throw;
}
}