set exception handler inside the runtime

This forum is meant for questions and discussions about the X# language and tools
User avatar
Chris
Posts: 4845
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

set exception handler inside the runtime

Post by Chris »

Hi Wolfgang,

One way would be to define an Event in the library, with information about the exception and intercept it from your core app. Something like:

Code: Select all

// in a VO dialect library:
DELEGATE ErrorHappenedDelegate(oError AS Exception) AS VOID

STATIC CLASS ErrorHandler
	STATIC EVENT ErrorHappened AS ErrorHappenedDelegate
	STATIC METHOD RaiseError(oError AS Exception) AS VOID
	IF ErrorHandler.ErrorHappened != NULL
		ErrorHandler.ErrorHappened(oError)
	END IF
	STATIC METHOD LinkErrorBlock() AS VOID
		ErrorBlock({|oError| ErrorHandler.RaiseError(oError)})
END CLASS
Then just call ErrorHandler.LinkErrorBlock() to set the new error block and subscribe to the event in your core app, like with

Code: Select all

// in the main core app:
ErrorHandler.ErrorHappened += MyErrorHandler

PROCEDURE MyErrorHandler(oError AS Exception)
? oError:ToString()
.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3748
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

Hi Chris,
this is great, thank you very much!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

set exception handler inside the runtime

Post by robert »

Wolfgang,
wriedmann wrote:Hi Chris,
maybe I'm stupid and don't see the wood because of the trees: but how I can do that?
My application is in Core dialect and does not knows about codeblocks, but the DLL knows about it (being in VO dialect).
But in case of an error e method of the main (Core dialect) application should be called.
How can I convert a function pointer passed from the application to a codeblock?
With the solution from Chris you do not need the codeblocks, but fyi the Core dialect does have the ICodeBlock interface. Each code block in X# (both compiler time code blocks as well as macro compiled codeblocks) knows this interface.
The interface is declared as

Code: Select all

INTERFACE ICodeblock
        METHOD	EvalBlock( args PARAMS OBJECT[]) AS OBJECT
        METHOD	PCount AS LONG
END INTERFACE
As you can see there is no Eval() method but an EvalBlock() method and this method takes an array of OBJECT values and
not an array of USUAL values.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3748
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

Hi Robert,
thank you very much!
I will give it a try.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply