th's picture

Exit game in constructor.. doesn't work

How i can exit my game before loading stuff in constructor?


doesnt work..


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Throw an exception. Don't allow the constructor to complete and return a semi-initialized object.

Application.Exit() only works in WinForms applications (i.e. GLControl) and won't have any effect on GameWindow apps.

th's picture

What kind of exception should i throw?

When i throw an exceptions, Visual Studio catch this exception, but i want exit game..

the Fiddler's picture

The exact exception depends on why you wish to exit the game. For example, NotSupportedException might be a good match if the hardware doesn't meet the minimum requirements of your game.

You can catch the exception yourself in the Main method and either exit silently or display an error message to the user (e.g. "Your hardware does not meet the minimum requirements"). The exact approach also depends on why you wish to exit the game.

th's picture

File not found exceptions, because, in constructor i load 3d model..

joo.. very thank :)