Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Void

Mental block with exceptions

This topic is 6945 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

__try, __finally is a MS extension to C exception handling, known as SEH (Structured Exception Handling)

It''s more for C like programming, which is what the win32 calls are..

You can read more about it in the MSDN documentation. Just search the index for "Structured Exception Handling"

Share this post


Link to post
Share on other sites
Advertisement
Xai: Thanks for the correction!

DerekSaw: Why not write a generic template resource class, with an operator T()? Templates to the rescue! If you want deallocation, add a virtual deallocate() = 0; function and just derive and override whatever you need. Of course, you could go all out then and add in copy constructors, an ownership flag, etc. but hey! -- you only write once!

Here's a sample derivation:


template
class resource_handle
{
public:
resource_handle(resource_type& resource) : m_resource(resource) {}
virtual ~resource_handle();

operator resource_type() { return m_resource; }

protected:
virtual void deallocate() = 0;

resource_type& m_resource;
};


class DC : public resource_handle
{
public:
DC();
virtual ~DC() { deallocate(); }

protected:
virtual void deallocate { ::ReleaseDC(m_resource); }
};


class thread : public resource_handle
{
public:
thread();
virtual ~thread() { deallocate(); }

protected:
deallocate() { SetEvent(m_stop_event); WaitForSingleObject(m_resource, INFINITE); }

HEVENT m_stop_event;
};


I have to go now, but you get the idea...also the derived classes are not quite complete yet.





- null_pointer
Sabre Multimedia


Edited by - null_pointer on May 17, 2000 8:47:49 AM

Share this post


Link to post
Share on other sites
A little too generic, maybe. Well, it sure looks nice. But I don''t need to be too generic since a simple constructor/destructor/operator could do the job and (IMHO) the overhead introduced is not worth it.

You still need to supply the body for the pure virtual and overload anything that is needed. In the end, it is like writing an independent class. BTW, your DC class here look almost the same as mine....

Share this post


Link to post
Share on other sites
DerekSaw: Windows handles are not the only thing that you can use with that class -- you can use anything, even shared memory or whatever, and not worry about copying, conversions, etc. I used a (slightly) more complex version in my library, and it works fine FILE* along with HINSTANCE - just less code in the derived classes, especially with overloaded operators. Think of it like auto_ptr on steriods.

(It''s modeled after Bjarne Stroustrop''s use of the word "resource" in his appendix on exceptions.)





- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
quote:
Original post by null_pointer

(It''s modeled after Bjarne Stroustrop''s use of the word "resource" in his appendix on exceptions.)



Duh. I don''t have the book. I can''t even find it here.
Anyone know there''s an complete downloadable online version... preferably in PDF.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!