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

TOPIC: Error handler for ported VO applications

Error handler for ported VO applications 27 Jul 2017 06:14 #2230

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • Hi,

    if you move your VO application to X#, unfortunately your error handler will not more work.

    Therefore you should change your Start module as follows:
    function Start() as int
      local oXApp as XApp
    
      AppDomain.CurrentDomain:UnhandledException += VOXSErrorHandler.UnhandledException
      try
        oXApp := XApp{}
        oXApp:Start()
      catch oException as Exception
        VOXSErrorHandler.ProcessException( oException )
      end try
    
      return 0

    And this is my error handler (also attached as prg file to this message):
    using System.Text  
    using System.IO    
    using System.Reflection
    
    static class VOXSErrorHandler
    	
    static constructor()
    	
      return
    	
    static method UnhandledException( Sender as object, e as UnhandledExceptionEventArgs ) as void
    		
      VOXSErrorHandler.ProcessException( ( Exception ) e:ExceptionObject )
    			
      return
    
    static method ProcessException( oException as Exception ) as void
      local cMessage as string
    	
      cMessage := oException:Message
      VOXSErrorHandler.WriteErrorLog( oException )
      do while oException:InnerException != NULL_OBJECT
        oException := oException:InnerException
        VOXSErrorHandler.WriteErrorLog( oException )
        cMessage += CRLF + oException:Message
      enddo
      VOXSErrorHandler.ErrBox( cMessage )
    	
      return
    	
    static method WriteErrorLog( oException as Exception ) as void
      local cFileName as string
      local cErrorText as string
      local oSB as StringBuilder
    
      cFileName := Path.Combine( AppDomain.CurrentDomain:BaseDirectory, "XSharpError.log" )
      oSB := StringBuilder{ String.Format( "Error occurred in {0} at {1}", ;
        Assembly.GetEntryAssembly():Location, DateTime.Now:ToString() ) }
      oSB:AppendLine( "------------------------------------------------------------" )
      oSB:AppendLine( oException:Message )
      oSB:AppendLine( "Callstack:" )
      oSB:AppendLine( oException:StackTrace )
      oSB:AppendLine( "" )
      File.AppendAllText( cFileName, oSB:ToString() )
    	
      return
    
    static method ErrBox( cText as string ) as void
      local oParent	as object
      local oBox as TextBox
    
      oParent := GetObjectByHandle( GetActiveWindow() )
      if oParent == null_object
        oParent := nil
      endif
      oBox := TextBox{ oParent, "Error", cText }
      oBox:Type := BOXICONHAND
      oBox:Beep := true
      oBox:Show()
    
      return
    
    end class

    Hope this helps someone!

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

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

    Error handler for ported VO applications 27 Jul 2017 11:06 #2232

  • FFF's Avatar

  • FFF


  • Posts: 919
  • Wolfgang Riedmann wrote:

      oParent := GetObjectByHandle( GetActiveWindow() )
      if oParent == null_object
        oParent := nil

    Wolfgang,
    thx for that.
    I try to understand what i use, so, a word to the above lines -> Null_Object vs. Nil ?

    TIA
    Karl
    Regards
    Karl (X# 2.4a; Xide 1.25; W8.1/64 German)

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

    Error handler for ported VO applications 27 Jul 2017 11:32 #2233

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • hi Karl,
    Answering from my phone.
    In the MessageBox class there is a check about the owner beimg nil, and AFAIK in the VO runtime there is a difference between nil and null_object.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Error handler for ported VO applications 27 Jul 2017 11:57 #2234

  • FFF's Avatar

  • FFF


  • Posts: 919
  • Wolfgang,
    that was in my mind, too. But a quick try in 2838 a la
    LOCAL oParent as OBJECT
    // IF oParent == null_object
    ? oParent := null_object, "Null_Obj"
    // end
    ? oParent == nil, "nil"
    showed no difference, regardless of how i construct the compare.

    Therefore my question...
    Regards
    Karl (X# 2.4a; Xide 1.25; W8.1/64 German)

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

    Error handler for ported VO applications 27 Jul 2017 12:25 #2235

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • Hi Karl,

    this is the code from the GUI classes:
    IF !IsNil(uParent)
    		IF !IsInstanceOfUsual(uParent, #Window)
    			WCError{#Init,#TextBox,__WCSTypeError,uParent,1}:@@Throw()
    		ELSE
    			oParent := uParent
    		ENDIF
    	ENDIF

    Therefore I have the NIL in my VO code, and copied from there to the error handler. This is very old code, was written at the times of VO 1.0.
    But of course you can change it as you like.

    My standard error handler in VO has also a print button, and the error text is shown in a MultiLineEdit. I have yet to construct such a dialog for X#, and of course there will 3 different windows: VO GUI, WinForms and WPF.

    This is only a working starting point - without such a handler it may be harder to find errors - therefore it writes also an error log in the program directory (I don't install my software in the "Program Files" structure because I'm using online updates that replace simply the executable and other files like the dictionary.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Error handler for ported VO applications 23 Aug 2017 15:41 #2450

  • hsc's Avatar

  • hsc


  • Posts: 126
  • Hi Wolfgang,

    He would use a similar errorhandler in the WPF new app in Xsharp?

    Juraj

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

    Error handler for ported VO applications 23 Aug 2017 15:51 #2451

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • Hi Juraj,

    the WPF errorhandler differs in the mode it displays the error.

    With the VO GUI classes, you can use TextBox class to display the error message since it is a part of the VO GUI classes.
    With WPF you should use a WPF window or, if you are using MVVM, a different possibility to show the error.

    Therefore I have 3 different error handlers:
    - for VO GUI
    - for WinForms
    - for WPF

    In my applications, all 3 use the same error logging routine (write to a file).

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Error handler for ported VO applications 23 Aug 2017 15:54 #2452

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • Hi Juraj,

    I would like to point you also to this message here in the forum:

    https://www.xsharp.info/forum/public-vo-vn/310-suggestions-for-conversion-vo-programs-using-vo-gui-classes?start=10#1984

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Error handler for ported VO applications 23 Aug 2017 16:09 #2453

  • hsc's Avatar

  • hsc


  • Posts: 126
  • Hi Wolfgang,

    Thank you for your response. You could send me an example as you do in the WPF app?

    Juraj

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

    Error handler for ported VO applications 23 Aug 2017 16:22 #2454

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • Hi Juraj,

    I have to extract the sample from my libraries.

    I will post a sample application tomorrow (I'm working out of office today until late).

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Error handler for ported VO applications 24 Aug 2017 09:35 #2463

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2232
  • Hi Juraj,

    I have attached a XIDE export file to this message, and you can find it also here:

    https://riedmann.it/download/WPFErrorHandler.viaef

    A few other samples are on the page here:

    https://riedmann.it/verschiedenes_vulcan.php

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

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

    • Page:
    • 1