Log in

View Full Version : Untyped Exception?


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?

IanB
25th September 2006, 00:09
catch (COVFileNotOpenedExcetion ex) {
env->ThrowError("COVReader: File couldn t be opened");
}
catch (COVFileDataExcetion ex) {
env->ThrowError("COVReader: Unexpected file s data");If you want to catch "xyzzy &" then throw "xyzzy &", if you throw "xyzzy" than you have to catch "xyzzy"

Sergejack2
26th September 2006, 13:46
I 'm expecting an answer about SEH.

catch (COVFileNotOpenedExcetion ex) {
env->ThrowError("COVReader: File couldn t be opened");
}
catch (COVFileDataExcetion ex) {
env->ThrowError("COVReader: Unexpected file s data");If you want to catch "xyzzy &" then throw "xyzzy &", if you throw "xyzzy" than you have to catch "xyzzy"

No.

Sergejack2
27th September 2006, 01:20
Ok, I got it.

I mixed up the syntax of the classical try...catch with the one enclosing the whole constructor wich automatically rethrow the exception.
So I just had to had thorw; at the end of the catch clause of COVReader's constructor.

stickboy
29th September 2006, 13:03
[code] catch If you want to catch "xyzzy &" then throw "xyzzy &", if you throw "xyzzy" than you have to catch "xyzzy"That's not true.

"throw Foo();" is certainly different from "throw new Foo();", though.