Sergejack2
24th September 2006, 23:27
I have a problem with exception handling in my avs filter.
COVExceptions.h
#include <exception>
class COVExcetion : public std::exception {};
class COVFileExcetion : public COVExcetion {};
class COVFileNotOpenedExcetion : public COVFileExcetion {};
class COVFileDataExcetion : public COVFileExcetion {};
COVReaderEngine.cpp
[...]
COVReaderEngine::COVReaderEngine(const char* s) {
fichier = new ifstream();
fichier->open(s, ios_base::in | ios_base::binary);
if (fichier->rdstate() != 0) {
delete fichier;
throw new COVFileNotOpenedExcetion();
}
fichier->seekg(0, ios::end);
endOfFile = fichier->tellg();
fichier->seekg(ios::beg);
// HEADER
{
char HEADER[4] = {'@', 'C', 'O', 'V'};
char* tmp = new char[4];
fichier->read(tmp,4);
if (memcmp(tmp,HEADER,4) != 0) {
delete[] tmp;
fichier->close();
delete fichier;
throw new COVFileDataExcetion();
}
}
[...]
Whenever I try to use this filter with a wrong fileName, I should get an avsException saying "COVReader: File couldn t be opened".
monFiltre.cpp
[...]
// constructor
COVReader::COVReader(PClip _child, const char *COVFile, IScriptEnvironment* env) : GenericVideoFilter(_child) {
[...]
try {
thisCOVReaderEngine = new COVReaderEngine(COVFile);
}
catch (COVExcetion) {
delete thisCOVReaderEngine;
throw;
}
[...]
}
[...]
Any exception should go up to the calling function.
monFiltre.cpp
[...]
AVSValue __cdecl Create_SimpleSample(AVSValue args, void* user_data, IScriptEnvironment* env) {
COVReader *myCOVReader;
myCOVReader = NULL;
try {
myCOVReader = new COVReader(args[0].AsClip(),args[1].AsString(),env);
}
catch (COVFileNotOpenedExcetion &ex) {
env->ThrowError("COVReader: File couldn t be opened");
}
catch (COVFileDataExcetion &ex) {
env->ThrowError("COVReader: Unexpected file s data");
}
catch (...) {
env->ThrowError("COVReader: Unexpected exception");
}
return myCOVReader;
}
[...]
Whenever I try to use this filter with a wrong fileName, I get an exception saying "COVReader: Unexpected exception" instead of the expected "COVReader: File couldn t be opened".
Can you help, pls?
COVExceptions.h
#include <exception>
class COVExcetion : public std::exception {};
class COVFileExcetion : public COVExcetion {};
class COVFileNotOpenedExcetion : public COVFileExcetion {};
class COVFileDataExcetion : public COVFileExcetion {};
COVReaderEngine.cpp
[...]
COVReaderEngine::COVReaderEngine(const char* s) {
fichier = new ifstream();
fichier->open(s, ios_base::in | ios_base::binary);
if (fichier->rdstate() != 0) {
delete fichier;
throw new COVFileNotOpenedExcetion();
}
fichier->seekg(0, ios::end);
endOfFile = fichier->tellg();
fichier->seekg(ios::beg);
// HEADER
{
char HEADER[4] = {'@', 'C', 'O', 'V'};
char* tmp = new char[4];
fichier->read(tmp,4);
if (memcmp(tmp,HEADER,4) != 0) {
delete[] tmp;
fichier->close();
delete fichier;
throw new COVFileDataExcetion();
}
}
[...]
Whenever I try to use this filter with a wrong fileName, I should get an avsException saying "COVReader: File couldn t be opened".
monFiltre.cpp
[...]
// constructor
COVReader::COVReader(PClip _child, const char *COVFile, IScriptEnvironment* env) : GenericVideoFilter(_child) {
[...]
try {
thisCOVReaderEngine = new COVReaderEngine(COVFile);
}
catch (COVExcetion) {
delete thisCOVReaderEngine;
throw;
}
[...]
}
[...]
Any exception should go up to the calling function.
monFiltre.cpp
[...]
AVSValue __cdecl Create_SimpleSample(AVSValue args, void* user_data, IScriptEnvironment* env) {
COVReader *myCOVReader;
myCOVReader = NULL;
try {
myCOVReader = new COVReader(args[0].AsClip(),args[1].AsString(),env);
}
catch (COVFileNotOpenedExcetion &ex) {
env->ThrowError("COVReader: File couldn t be opened");
}
catch (COVFileDataExcetion &ex) {
env->ThrowError("COVReader: Unexpected file s data");
}
catch (...) {
env->ThrowError("COVReader: Unexpected exception");
}
return myCOVReader;
}
[...]
Whenever I try to use this filter with a wrong fileName, I get an exception saying "COVReader: Unexpected exception" instead of the expected "COVReader: File couldn t be opened".
Can you help, pls?