error loading and file handling

hello. i have not programmed in c++ in years. how can i catch or handle and exception… such as

FSPathMakeRef failed -43
ERROR LOADINGmovie

or how can i check if the file exists before loading the movie?

thanks.

there are currently no exceptions built into OF - but you can definitely test if a file exists (replace *** with the name of the file you care about):

  
  
bool bFileThere = false;  
fstream fin;  
string fileNameInOF = ofToDataPath("***"); // since OF files are in the data directory, we need to do this  
fin.open(fileNameInOF.c_str(),ios::in);  
if ( fin.is_open() ) {  
    cout<<"file exists"<<endl;  
    bFileThere =true;  
}  
fin.close();  
  
if (bFileThere) {  
    ; //  have fun !!  
}  
  

be sure to add this at the top of the .cpp file, for example, in testApp.cpp just below #include “testApp.h”

  
  
#include <fstream>  
  

best,
zach

thanks for the response zach ill trying adding this to my project this evening.

Many years later… searching for same issue.
There is now a whole wonderland of convenient
oF File utilities
including
ofFile::doesFileExist(fileName)