How to catch unhandled exceptions thrown by custom language dll in Client App

SyntaxEditor for WPF Forum

The latest build of this product (v24.1.5) was released 2 months ago, which was before this thread was created.
Posted 6 days ago by Rick - Developer, Visual Software Systems LLC
Version: 24.1.2
Avatar

I've written a custom language server for a SQL-like language using the language designer and have implemented it as a C# DLL that my client application consumes.  I'm trying to find a way to catch unhandled exceptions thrown by the language server in my client app so I can log the error, gracefully shutdown the language server, and fall back to the .langdef created out of the same Language Designer project without my client app terminating.  I can't use app Dispatcher.UnhandledException event becauase the server isn't running on the UI thread.  I have looked at the AppDomain.UnhandledException event but that doesn't give the option to prevent the client application from terminating like the Dispatcher.UnhandledException event does and I don't see any kind of event on SyntaxEditor that provides that kind of feedback.  

Any idea how I can accomplish this?

Thanks.

Comments (4)

Posted 5 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

I'm curious what kind of unhandled exceptions you'd plan on seeing?  In general, you should be able to design your lexer, parser, etc. language services with proper structured exception handling within the code itself so there never is an unhandled exception.  If you did encounter some scenario where something needed restarted (or switching to a lesser version of the syntax language), you could make a custom event sink service and call into that when the scenario occurs.  The event sink could possibly have a method that adjusts the registered services on the syntax language to unregister ones for your language server and register new ones needed for a .langdef-oriented setup.


Actipro Software Support

Posted 5 days ago by Rick - Developer, Visual Software Systems LLC
Avatar

Thanks.  My original thought was to let the client catch any error thrown by the language server since so I can log it and shut it down. But that's not going to work given that I can't mark the event handled and let the client continue running.  Using a custom event sink service to communicate back to the client is a good alternative.  Can you provide guidance/example on how to create a custom event sink service and call it? I can't find anything in the docs other than that it can be done.

Posted 4 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

Our event sinks get called through some internal methods.  The event sink concept is geared for public broadcast of some event.  If you only have one bit of logic that would ever occur in this scenario, it would be easiest to make a simple class instead of implementing the event sink concept.  Here's some quick steps to do that.

1) Make class MyLanguageErrorProcessor that has a method to call when the language error occurs.

2) Register that MyLanguageErrorProcessor as a language service on the ISyntaxLanguage using a call like language.RegisterService(new MyLanguageErrorProcessor()).

3) When your code detects a language error scenario, get the ISyntaxLanguage instance and call the language.GetService<MyLanguageErrorProcessor>() method to get the instance of your processor class.

4) Invoke your processor's method and do whatever logic you need within that.

I hope that helps.


Actipro Software Support

Posted 4 days ago by Rick - Developer, Visual Software Systems LLC
Avatar

Exactly what I needed and works perfectly.  Thank you!

Add Comment

Please log in to a validated account to post comments.