ofVideoGrabber + device not connected

I’ve made a simple motion tracking application that ables the user to choose which device he wants to use. The problem is, when he chooses a device that is not connected, my app just crashes. Is there anyway i can fix it? Something like:

if(device1 *isnt connected*) {
   *connect to another device;*


You could use the ofVideoGrabber listDevices() and see if any of the devices that the function return matches your selected device and then try to set the grabber.