__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"
Mental block with exceptions
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:
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
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
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....
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....
"after many years of singularity, i'm still searching on the event horizon"
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
(It''s modeled after Bjarne Stroustrop''s use of the word "resource" in his appendix on exceptions.)
- null_pointer
Sabre Multimedia
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.
"after many years of singularity, i'm still searching on the event horizon"
Bjarne Stroustrop''s Home Page
You might have to do a bit of digging, but there are several appendices online (in PDF) for his book (which is not online). You can look for the online appendix on exceptions by clicking on the link for the book.
- null_pointer
Sabre Multimedia
You might have to do a bit of digging, but there are several appendices online (in PDF) for his book (which is not online). You can look for the online appendix on exceptions by clicking on the link for the book.
- null_pointer
Sabre Multimedia
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement