Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

set exception handler inside the runtime 20 Oct 2021 11:42 #19981

  • wriedmann
  • wriedmann's Avatar
  • Topic Author


  • Posts: 2836
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 12:28 #19984

    • ic2


  • Posts: 1183
  • Hello Wolfgang,

    At the end of the last session
    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

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 12:30 #19985

    • ic2


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

    Dick

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 12:53 #19986

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 13:35 #19990

    • Chris
    • Chris's Avatar


  • Posts: 2860
  • 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.

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 13:43 #19992

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • Hi Chris,

    thank you very much, I will try that.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 15:56 #19995

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 16:02 #19997

    • Meinhard
    • Meinhard's Avatar


  • Posts: 64
  • 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

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 16:06 #19998

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 16:12 #19999

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • Hi Chris,
    I think, I have found it (at least it works).
    In my VO dialect library I have that static method:
    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:
    rdm.XbaseInterface.VOInterface.SetExceptionHandler( self, "ProcessExceptionRT" )
    whereas the called method is this one:
    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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 16:18 #20001

    • Chris
    • Chris's Avatar


  • Posts: 2860
  • 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:

    // 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

    // in the main core app:
    ErrorHandler.ErrorHappened += MyErrorHandler
    
    PROCEDURE MyErrorHandler(oError AS Exception)
    ? oError:ToString()

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    set exception handler inside the runtime 20 Oct 2021 16:23 #20002

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • Hi Chris,
    this is great, thank you very much!
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 16:57 #20009

    • robert
    • robert's Avatar


  • Posts: 2475
  • 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
    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

    Please Log in or Create an account to join the conversation.

    set exception handler inside the runtime 20 Oct 2021 17:09 #20011

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 2836
  • Hi Robert,
    thank you very much!
    I will give it a try.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1