Unhandled Exceptions in a Plugin

Discussions relating to plugin development, and the Jiwa API.

Unhandled Exceptions in a Plugin

Postby SBarnes » Thu Dec 13, 2018 5:07 pm

Is there a way either with some plugin code or setting to get Jiwa to log any unhandled exceptions in a plugin to say the application log rather than just getting the message box of the error?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1620
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Unhandled Exceptions in a Plugin

Postby Mike.Sheen » Thu Dec 13, 2018 5:13 pm

Hi Stuart,

Maybe... We display those messageboxes by adding a handler for the UnhandledException and ThreadException in the Jiwa.Exe form. In theory a plugin could do the same.

The adding of the handlers:
Code: Select all
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf UnhandledExceptionHandler
AddHandler System.Windows.Forms.Application.ThreadException, AddressOf UnhandledFormExceptionHandler


The handlers themselves:
Code: Select all
Private Sub UnhandledExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
   If TypeOf e.ExceptionObject IsNot JiwaApplication.Exceptions.ClientCancelledException Then
      If DirectCast(e.ExceptionObject, System.Exception).Data.Contains("Custom Message") Then
         ReportError(DirectCast(e.ExceptionObject, System.Exception).Data("Custom Message"), DirectCast(e.ExceptionObject, System.Exception).GetBaseException.TargetSite.Name)
      Else
         ReportError(DirectCast(e.ExceptionObject, System.Exception).GetBaseException.Message, DirectCast(e.ExceptionObject, System.Exception).GetBaseException.TargetSite.Name)
      End If

   End If
End Sub

Private Sub UnhandledFormExceptionHandler(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
   If TypeOf e.Exception IsNot JiwaApplication.Exceptions.ClientCancelledException Then
      If e.Exception.Data.Contains("Custom Message") Then
         ReportError(e.Exception.Data("Custom Message"), e.Exception.GetBaseException.TargetSite.Name)
      Else
         ReportError(e.Exception.GetBaseException.Message, e.Exception.GetBaseException.TargetSite.Name)
      End If
   End If
End Sub


Have fun!
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Unhandled Exceptions in a Plugin

Postby SBarnes » Fri Dec 14, 2018 7:11 am

Hi Mike,

I had a stab at this, all the events hook up ok but nothing fires and Jiwa just still reports the error as normal, any ideas?
Attachments
Plugin Attkey Plugin Exception Catcher.xml
(31.87 KiB) Downloaded 97 times
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1620
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Unhandled Exceptions in a Plugin

Postby Mike.Sheen » Fri Dec 14, 2018 5:02 pm

Hi Stuart,

I moved these 3 lines in your plugin into the Setup method of the ApplicationManagerPlugin and your handlers are being invoked upon exception:
Code: Select all
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += PluginUnhandledExceptionHandler;
System.Windows.Forms.Application.ThreadException += PluginUnhandledFormExceptionHandler;


Plugin attached is yours with the above change.

Mike
Attachments
Plugin Attkey Plugin Exception Catcher.xml
(32.02 KiB) Downloaded 64 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Unhandled Exceptions in a Plugin

Postby SBarnes » Fri Dec 14, 2018 5:30 pm

Hi Mike,

I loaded your version in and it still won't work, where were you throwing the exception from I have been trying to do it from another plugin, even tried changing the executing order so the catcher was called first?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1620
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 11 guests