Try catch with ofVideoPlayer

Hey all,
I’m trying to setup a try catch block with an array of ofVideoPlayer objects and I’m not sure what exactly to catch should videoPlayer.loadMovie(fname); goes wrong.

void testApp::setupVideos(){
    for (int i = 1; i<= NUMVIDEOS; ++i) {
        string fname = "horse_video_";
        fname.append(ofToString(i)).append(".mov");
        cout <<"movie file name: "<< fname << endl;
        try {
            videos[i].loadMovie(fname);
        } catch(exception& e){
            cout << "couldn't load it" << endl;
        }
    }
    
    
}

It doesn’t seem to catch anything and still crashes. Am i catching the wrong thing or is there a better way of doing this?

In C++ and particularly in OF unlike, say Java you can’t expect a try/catch to grab all errors. You can use ofFile or another similar object to ensure you have a valid file before trying to load it into the ofVideoPlayer instance.

makes sense. Just wasn’t sure if I was missing something or not. Thanks!

also loadMovie returns false if it couldn’t open the video. also the app shouldn’t crash anyway so there must be a bug somewhere if it’s crashing for you, which platform are you using?

@arturo i found that the error actually, like u said isn’t from the loadMovie() call, but rather with my loop itself.

With the way I initially set it up the loop would make for properly structured file names which ranged from 1 - 5 but arrays obviously starting at 0 ranged from 0 - 4. So the last iteration of the loop at it is would be looking for videos[5] because of the i<=NUMVIDEOS; part. Saw that and fixed it a little later and that solved that problem.

but good to know that loadMovie returns a boolean though so I could theoretically just do
if(videos[i-1].loadMovie(fname)) //do stuff instead of the try catch block.