set exception handler inside the runtime

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

Hello Robert or Chris,
how do I set an my own error handler inside the X# runtime (specifically the RDD) when using a Core dialect application?
To specify it better: I have a command line X# application that is called by the task scheduler in Windows and does something.
Therefore, when en exception occurs, no messagebox can be shown, but an email should be sent using a personalized exception handler.
The application is written in Core dialect and is using a VO dialect library to access DBF files.
Thank you very much!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

set exception handler inside the runtime

Post by ic2 »

Hello Wolfgang,

At the end of the last session https://www.youtube.com/watch?v=qvbqxGt0zgQ I understood that a preprocessor script could take over global error handling (a bit like Ralph's error classes can do for VO).

On Robert's (large) to do list there is the promise that he will post a sample to do so, after my question.

Maybe that sample answers your question?

Dick
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

set exception handler inside the runtime

Post by ic2 »

Has everyone noticed that in the YouTube screenshot Robert looks like a pirate, with the Play icon on his left eye? :lol:

Dick
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

Hi Dick,
yes, I looked at that session on Youtube, but unfortunately it does not answers my question.
I already have an exception handler active in my application, but it is not called if any exception occurs inside the RDD classes.
So there must be any functionality to set an own error handler in the RDD classes.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

set exception handler inside the runtime

Post by Chris »

Hi Wolfgang,

You can just use ErrorBlock() and provide your own error handling. Something like

ErrorBlock({|oError| MyErrorHandler(oError)})

PROCEDURE MyErrorHandler(oError AS Exception)
? oError:ToString()

If your main exe is in Core and it does not know about codeblocks etc, you can do this in teh VO dialect library instead.

.
Chris Pyrgas

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

set exception handler inside the runtime

Post by wriedmann »

Hi Chris,

thank you very much, I will try that.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

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?
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Meinhard
Posts: 81
Joined: Thu Oct 01, 2015 4:51 pm

set exception handler inside the runtime

Post by Meinhard »

Hi Wolfgang,

I strongly recommend to look into MS Enterprise Library Exception Handling Block. The secret is to have different policies, depending on the environment, which actually handle the exception, without the need to handle this in your code, as you can incluence the setup of the exception handling by configuration.

Regards
Meinhard
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

Hi Meinhard,
I already have my error handlers in place.
My problem is how to make the X# runtime call my Core dialect error handler when there is a runtime error inside the X# runtime (specifically in the RDD).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

set exception handler inside the runtime

Post by wriedmann »

Hi Chris,
I think, I have found it (at least it works).
In my VO dialect library I have that static method:

Code: Select all

static method SetExceptionHandler( oObject as object, cMethodName as string ) as void
ErrorBlock( {|o| Send( oObject, String2Symbol( cMethodName ), o ), _Break( o ) } )
return
and the relative call is that here:

Code: Select all

rdm.XbaseInterface.VOInterface.SetExceptionHandler( self, "ProcessExceptionRT" )
whereas the called method is this one:

Code: Select all

method ProcessExceptionRT( oEx as Exception ) as void
self:WriteLog( oEx:Message )
self:WriteLog( oEx:StackTrace )
self:SendMail( "Fehler in BNBatchProcessor aufgetreten", oEx:Message, ProgSettings.ErrorMailTo, false )
return
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply