Re: c++ exceptions
Re: c++ exceptions
- Subject: Re: c++ exceptions
- From: Joel Reymont <email@hidden>
- Date: Tue, 16 Mar 2010 07:55:45 +0000
This thread on the USB list is the reason I ask:
http://groups.google.com/group/darwin-usb/browse_thread/thread/11d9e323f310f9a6
Configuring USB devices requires a lot of error checking and various resources are acquired as you move along the way. At a minimum, a device needs to be acquired, then the interface to that device. If you want to store these handles in a structure of your own then you need to allocate that and save the handles.
The device needs to be opened before the interface can be acquired and then the interface needs to be opened. If anything fails then the cleanup needs to be in reverse order, i.e.
6) Delete your structure from an internal list if you have stored it.
5) Dispose of your structure if you have allocated it.
4) Close the interface if you have opened it.
3) Release the handle to the interface if you have acquired it (it's not NULL).
2) Close the device if you have opened it.
1) Release the device handle if you have acquired it.
This leads to some ugly code without exceptions, witness the thread above, so I'm trying to figure out if there's a better way. My code is encapsulated in a framework so I'm thinking I could use exceptions without letting them escape the shared library.
Thanks, Joel
---
http://es.linkedin.com/in/joelreymont
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden