Using the latest g++, there appears to be a strange quirk in one of my try/catch blocks.
This refuses to compile:
But if I add an extra catch block in (at the deepest indentation) there are no errors...Code:void Method::run(ScopeContext* context){ Variable** paramVars = new Variable*[nParms]; ScopeContext* methodContext = new ScopeContext(context->getLevelObjectList(0)); try{ methodContext->incrementScope(); MethodParamSet* paramVals= context->getMethodParams(); for(int i=0; i<nParms; ++i){ paramVars[i] = new Variable(parms[i].name, paramVals->parms[i]); methodContext->addObject(paramVars[i]); } if(context->getThisObject()!=0){ Value* thisObj = context->getThisObject(); if(thisObj->type.isClassInstance()){ try{ ClassInstance* inst = (ClassInstance*) thisObj->ptr; inst->enterScope(methodContext, PRIVATE); }catch(InvalidScopeSetup iss){} } Variable* var = new Variable("this",thisObj); try{ methodContext->addObject(var); }catch(InvalidScopeSetup except){ throw OperationException("Cannot use this as a parameter to a class-method."); } } ActionChain::run(methodContext); }catch(ReturnValue ret){ if((ret.returned==0&&(!this->ret.isPrimitive()||this->ret.getValue().pType!=VOID)) ||(ret.returned!=0&&ret.returned->type!=this->ret)){ throw OperationException("No value returned from a method returning a value, or wrong type returned. Occured " + getAtLineStr()); } returned=ret.returned; } delete methodContext; for(int i=0; i<nParms; ++i){ delete paramVars[i]; } delete[] paramVars; }
Any insight? I would've expected the second to give an error, if anything, as I'm catching the same exception twice. I doubt it will affect how my code runs, but it struck me as very odd.Code://Surrounding code of the catch block if(context->getThisObject()!=0){ Value* thisObj = context->getThisObject(); if(thisObj->type.isClassInstance()){ try{ ClassInstance* inst = (ClassInstance*) thisObj->ptr; inst->enterScope(methodContext, PRIVATE); }catch(InvalidScopeSetup iss){ }catch(InvalidScopeSetup iss){}//why do I need two? } Variable* var = new Variable("this",thisObj); try{ methodContext->addObject(var); }catch(InvalidScopeSetup except){ throw OperationException("Cannot use this as a parameter to a class-method."); } }




Reply With Quote