Skip to content

Commit 99bf693

Browse files
committed
Corrected SAMPLE function throw invalid sample
1 parent e82b123 commit 99bf693

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/interpreter/languagedefinitions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ void CS::Functions::sample() {
3131

3232
LiteralValue* argValue = ctx->getArgumentValue("fileName");
3333
if( argValue->getDataTypeId() != DataTypesId::String )
34-
throw new SemanticException("Invalid argument for sample function. Expected a file name");
34+
throw SemanticException("Invalid argument for sample function. Expected a file name");
3535

3636
string fileName = *(string*)argValue->getValue();
3737

3838
AudioFile<float> a;
39-
a.load(fileName);
39+
if( !a.load(fileName) )
40+
throw SemanticException("File not found or invalid file format.");
41+
4042
ctx->newAudioFile(fileName,a);
4143

4244
Sample tmp(fileName);

src/interpreter/values/executionlinkedvalue.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,14 @@ LiteralValue* ExecutionLinkedValue::getValue() const {
9494
unique_ptr<LiteralValue> intermediateValue = nullptr;
9595
if( _name == get<0>(_methodsList.front()) )
9696
{
97-
if( !Context::getInstance()->executeFunction(_name,get<1>(_methodsList.front())->getValue()) )
98-
throw SemanticException("Unknown function name", this->getCodeReference());
97+
try {
98+
if( !Context::getInstance()->executeFunction(_name,get<1>(_methodsList.front())->getValue()) )
99+
throw SemanticException("Unknown function name", this->getCodeReference());
100+
}
101+
catch(const SemanticException& e)
102+
{
103+
throw SemanticException(e.what(),this->getCodeReference());
104+
}
99105
intermediateValue = unique_ptr<LiteralValue>(Context::getInstance()->getReturnValue());
100106
}
101107
else
@@ -107,8 +113,14 @@ LiteralValue* ExecutionLinkedValue::getValue() const {
107113

108114
if( firstMethod )
109115
{
110-
if( !Context::getInstance()->executeMethod(_name,get<0>(method),args.get()) )
111-
throw SyntaxException("Unknown method name",get<1>(method)->getCodeReference());
116+
try {
117+
if( !Context::getInstance()->executeMethod(_name,get<0>(method),args.get()) )
118+
throw SyntaxException("Unknown method name",get<1>(method)->getCodeReference());
119+
}
120+
catch(const SemanticException& e)
121+
{
122+
throw SemanticException(e.what(),get<1>(method)->getCodeReference());
123+
}
112124
firstMethod = false;
113125
intermediateValue = unique_ptr<LiteralValue>(Context::getInstance()->getReturnValue());
114126
}

0 commit comments

Comments
 (0)