diff --git a/alib2cli/src/environment/Environment.h b/alib2cli/src/environment/Environment.h index 993e2bc0f9e1e07218611abf9b3072a6c969138a..c9200a628576babde9a7c71487e71481fb0c68b0 100644 --- a/alib2cli/src/environment/Environment.h +++ b/alib2cli/src/environment/Environment.h @@ -67,7 +67,10 @@ public: template < class T > const T & getVariable ( const std::string & name ) { - return std::dynamic_pointer_cast < abstraction::ValueProvider < const T & > > ( getVariableInt ( name ) )->getConstValueReference ( ); + std::shared_ptr < abstraction::ValueProvider < const T & > > ptr = std::dynamic_pointer_cast < abstraction::ValueProvider < const T & > > ( getVariableInt ( name ) ); + if ( ! ptr ) + throw exception::CommonException ( "Invalid variable type. Requested: " + ext::to_string < T > ( ) + ", actual : " + getVariableInt ( name )->getRuntimeReturnType ( ) ); + return ptr->getConstValueReference ( ); } void setVariable ( std::string name, std::shared_ptr < abstraction::OperationAbstraction > value ) {