diff --git a/src/interpreter/languagedefinitions.cpp b/src/interpreter/languagedefinitions.cpp index 91fc758..228f23e 100644 --- a/src/interpreter/languagedefinitions.cpp +++ b/src/interpreter/languagedefinitions.cpp @@ -31,12 +31,14 @@ void CS::Functions::sample() { LiteralValue* argValue = ctx->getArgumentValue("fileName"); if( argValue->getDataTypeId() != DataTypesId::String ) - throw new SemanticException("Invalid argument for sample function. Expected a file name"); + throw SemanticException("Invalid argument for sample function. Expected a file name"); string fileName = *(string*)argValue->getValue(); AudioFile a; - a.load(fileName); + if( !a.load(fileName) ) + throw SemanticException("File not found or invalid file format."); + ctx->newAudioFile(fileName,a); Sample tmp(fileName); diff --git a/src/interpreter/values/executionlinkedvalue.cpp b/src/interpreter/values/executionlinkedvalue.cpp index 105cc43..c18fcd6 100644 --- a/src/interpreter/values/executionlinkedvalue.cpp +++ b/src/interpreter/values/executionlinkedvalue.cpp @@ -94,8 +94,14 @@ LiteralValue* ExecutionLinkedValue::getValue() const { unique_ptr intermediateValue = nullptr; if( _name == get<0>(_methodsList.front()) ) { - if( !Context::getInstance()->executeFunction(_name,get<1>(_methodsList.front())->getValue()) ) - throw SemanticException("Unknown function name", this->getCodeReference()); + try { + if( !Context::getInstance()->executeFunction(_name,get<1>(_methodsList.front())->getValue()) ) + throw SemanticException("Unknown function name", this->getCodeReference()); + } + catch(const SemanticException& e) + { + throw SemanticException(e.what(),this->getCodeReference()); + } intermediateValue = unique_ptr(Context::getInstance()->getReturnValue()); } else @@ -107,8 +113,14 @@ LiteralValue* ExecutionLinkedValue::getValue() const { if( firstMethod ) { - if( !Context::getInstance()->executeMethod(_name,get<0>(method),args.get()) ) - throw SyntaxException("Unknown method name",get<1>(method)->getCodeReference()); + try { + if( !Context::getInstance()->executeMethod(_name,get<0>(method),args.get()) ) + throw SyntaxException("Unknown method name",get<1>(method)->getCodeReference()); + } + catch(const SemanticException& e) + { + throw SemanticException(e.what(),get<1>(method)->getCodeReference()); + } firstMethod = false; intermediateValue = unique_ptr(Context::getInstance()->getReturnValue()); }