Exceptions question

Hello,
I’ve came across such error message:
Error: Return type mismatch

it happens when the exception is supposed to be thrown in such code:

dataManager::vtPair* dataManager::getVtColumn(const char* keyname) throw(dataManager::dataException) { dataManager::vtPair *result = NULL; result = (dataManager::vtPair*)(vtColumns->GetValue(keyname)); if (result==NULL) { cerr << "::CARROT result==NULL; key:" << keyname << endl; throw (dataException("AQQ")); } return result; }

and the full output is like this:

::CARROT result==NULL; key:C Error: Return type mismatch getVtColumn() FILE:R.C LINE:133 *** Interpreter error recovered ***

Any suggestions what should I change?

Hi Milosz,

I can not reproduce this problem. Could you send me an example reproducing it (with carrot).

Cheers,
Philippe.

[code]#include
#include
#include

class dataManager {
protected:
TMap vtColumns;
public:
dataManager();
virtual ~dataManager();
Pair
getVtColumn(const char* keyname) throw(dataManager::dataException);
class dataException : public exception {
TString reason;
public:
dataException(TString msg) {
reason = "::dataException: " + msg;
}
~dataException() throw() {}
const TString what() const throw() {
return reason;
}
};
class vtPair {
private:
Float_t *data;
int count;
public:
vtPair(Float_t d, int c) {
data = d;
count = c;
}
~vtPair() {
if (data!=NULL)
//delete[] data;
free(data);
}
Float_t
getData() {
return data;
}
int getCount() {
return count;
}
};
};
dataManager::dataManager() {
vtColumns = new TMap();
}
dataManager::~dataManager() {
if(vtColumns!=NULL) {
TIterator it = vtColumns->MakeIterator();
TObject key;
while(key=(it->Next())) {
dataManager::vtPair tmp = (dataManager::vtPair)(vtColumns->GetValue(key));
if(tmp!=NULL)
delete tmp;
}
}
}
dataManager::vtPair
dataManager::getVtColumn(const char
keyname) throw(dataManager::dataException) {
dataManager::vtPair result = NULL;
result = (dataManager::vtPair
)(vtColumns->GetValue(keyname));
if (result==NULL) {
cerr << “::CARROT result==NULL; key:” << keyname << endl;
throw (dataException(“dataManager::getVtColumn” + TString(keyname)));
}
return result;
}

void TEST() {
TSQLResult *result;
try {
dataManager *a = new dataManager();
a->getVtColumn(“A”);
} catch (dataManager::dataException e1) {
cout << e1.what << endl;
}
}[/code]

The example as for now is `carrotless’ and a bit stripped down, but the error remains:

::CARROT result==NULL; key:A Error: Return type mismatch getVtColumn() FILE:TEST.C LINE:67 *** Interpreter error recovered ***

ROOT version: 3.10/02

Regards,

Hi,

To make it work properly in CINT replace:

with

I.e. drop the surrounding paranthesis.

Cheers,
Philippe.

[quote=“pcanal”]To make it work properly in CINT replace:

with

I.e. drop the surrounding paranthesis.
[/quote]

Hi!
Unfortunatelly in my environment - even if I just state such thing:

throw 1; I still get mentioned previously message.
I’m using ROOT 3.10/02. What else should I look at?

Regards,

Hi,

I will check into it.
However, I recommend that you start using compiled script instead of interpreted script. This can be done simply by using ACliC (i.e. just add a ‘+’ to your filename when loading it.

Cheers,
Philippe