Jump to content
  • Advertisement
Sign in to follow this  
Fire Lancer

Error handeling problem

This topic is 3560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In general I use exceptions to deal with errors, however the problem I have here is that the error applies to a diffrent thread than the one that caused it. Basicly the window has its own thread, and the direct3d device must be created and reset by the same thread that created the window. However creating the device may fail, so I need to throw an exception in the thread that was trying to create the instance, not the window code The callback function:
void Callback(HWND hwnd, boost::function<void(HWND,LPARAM)> call, LPARAM lParam)
	//Make our stack allocated function object into a heap allocated one
	boost::function<void(HWND,LPARAM)> *callH = new boost::function<void(HWND,LPARAM)>(call);
	//send a message with a pointer to our function object in the WPARAM
	PostMessage(hwnd, WM_CALLBACK, (unsigned)callH, lParam);
	//check for our custom message
	if(msg == WM_CALLBACK)
		//retreive the function pointer from the WPARAM
		boost::function<void(HWND,LPARAM)> *callH = (boost::function<void(HWND,LPARAM)>*)wParam;
		//call it
		//delete our heap allocated function object
		delete callH;
		return 0;
		//if there was nothing relevant to us, call the old message procedure
		return CallWindowProc(hooked[hwnd], hwnd, msg, wParam, lParam);
//std::map<HWND, WNDPROC> hooked;

The code that requests the window thread to create the device
Graphics::Graphics(IWindow *_window, Size2<unsigned> _size)
:lost(false), reset(false), refCnt(0), backCol(0xFF000000),
started(false), exited(false),
window(_window), size(_size)
	HWND hwnd = *((HWND*)window->GetHandle());
	Callback(hwnd, boost::bind(&Graphics::create, this), 0);

void Graphics::create()
...code that may throw various exceptions
	started = true;

So basicy I somehow need to catch any exceptions in Graphics::create() and rethrow them from the constructor... Is there some way to do this that still lets me go to the source of the exception in the case of an unhandled exception?

Share this post

Link to post
Share on other sites
In terms of twiddling debugger settings, there's Break When an Exception is Thrown.

  1. On the Debug menu, click Exceptions.
  2. In the Exceptions dialog box, select Thrown for an entire category of exceptions, for example, Common Language Runtime Exceptions.

Poking around MSDN (not at a computer with VS installed), it looks like 'C++ exceptions' is a category you could do this for.

Of course, if you're not using Visual Studio, this is no help whatsoever!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!