XIDE Adventure

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

XIDE Adventure

Post by OhioJoe »

When I run a test application in XIDE it shows a black error screen that quickly disappears.
How can I capture that error?
Is it saved somewhere? Is there a setting I've missed?
Joe Curran
Ohio USA
User avatar
wriedmann
Posts: 3783
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: XIDE Adventure

Post by wriedmann »

Hi Joe,
what is your Start() method? And are you talking about a VOGUI Classes application?
Anyway: try to put similar code in your Start() method:

Code: Select all

[STAThread];
function Start() as void

	try

	// Ein eigenes APP-Object setzen
	oApp		:= EnhancedApp{}
	__SetAppObject( oApp )

	oApp:Start()

	catch oEx as Exception

	VOXSErrorHandler.ProcessException( oEx )

	end try

	return 0
And this is my Error handler:

Code: Select all

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	
After an exception you should find a XSharpError.log file in your application folder.
To have code lines in it you have to compile with Debug set to on.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1589
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: XIDE Adventure

Post by FFF »

Joe,
i'd suspect, your app is a console app and in Xide unter Tools/Preferences/General the setting "Add pause in console applications" is NOT set. Set it, and the screen will stay ;-)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Re: XIDE Adventure

Post by OhioJoe »

Thank you both. It is a console app that I'm using to test some basic SQL routines.

Karl: That box is checked.

Wolfgang: I'll try to write an error handler based on the example you provided.

The adventure continues!
Joe Curran
Ohio USA
User avatar
Chris
Posts: 4977
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: XIDE Adventure

Post by Chris »

Hi Joe,

A cut down sample from Wolfgang's more sophisticated error handler, that will also do the job for simple test apps:

Code: Select all

FUNCTION Start() AS VOID
TRY

// do stuff

CATCH e AS Exception
	? "Error happened:"
	? e:ToString()
END TRY
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply