diff --git a/dynare++/parser/cc/dynamic_atoms.cpp b/dynare++/parser/cc/dynamic_atoms.cpp
index f02b580af1281f094a69b06bc60c268695734146..ca6b6dcd219158d9faf22f76da01c2c5ea460332 100644
--- a/dynare++/parser/cc/dynamic_atoms.cpp
+++ b/dynare++/parser/cc/dynamic_atoms.cpp
@@ -341,6 +341,12 @@ int DynamicAtoms::index(const char* name, int ll) const
 	return -1;
 }
 
+bool DynamicAtoms::is_referenced(const char* name) const
+{
+	Tvarmap::const_iterator it = vars.find(name);
+	return it != vars.end();
+}
+
 const DynamicAtoms::Tlagmap& DynamicAtoms::lagmap(const char* name) const
 {
 	Tvarmap::const_iterator it = vars.find(name);
diff --git a/dynare++/parser/cc/dynamic_atoms.h b/dynare++/parser/cc/dynamic_atoms.h
index 03cb0411fdc1ff8f54b4e4bc07ae6621324362af..7d44d6dcc2e71faa4066145281b9229dbd6c7bc5 100644
--- a/dynare++/parser/cc/dynamic_atoms.h
+++ b/dynare++/parser/cc/dynamic_atoms.h
@@ -182,6 +182,9 @@ namespace ogp {
 		/** Return index of the variable described by the variable
 		 * name and lag/lead. If it doesn't exist, return -1. */
 		int index(const char* name, int ll) const;
+		/** Return true if a variable is referenced, i.e. it has lag
+		 * map. */
+		bool is_referenced(const char* name) const;
 		/** Return the lag map for the variable name. */
 		const Tlagmap& lagmap(const char* name) const;
 		/** Return the variable name for the tree index. It throws an
diff --git a/dynare++/parser/cc/static_atoms.cpp b/dynare++/parser/cc/static_atoms.cpp
index 0151cade68f2c66c2c7a83e6f3f39bc634b3e799..7276cc0c9a90e9b40dd39f0a6dff566e99e317de 100644
--- a/dynare++/parser/cc/static_atoms.cpp
+++ b/dynare++/parser/cc/static_atoms.cpp
@@ -41,15 +41,14 @@ void StaticAtoms::import_atoms(const DynamicAtoms& da, OperationTree& otree, Tin
 		register_name(name);
 		int tnew = otree.add_nulary();
 		assign(name, tnew);
-		try {
-			const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
+        if (da.is_referenced(name)) {
+            const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
 			for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
 				 it != lmap.end(); ++it) {
 				int told = (*it).second;
 				tmap.insert(Tintintmap::value_type(told, tnew));
 			}
-		} catch (const ogu::Exception& e) {
-		}
+        }
 	}
 }
 
diff --git a/dynare++/src/dynare_atoms.cpp b/dynare++/src/dynare_atoms.cpp
index e0121d5306c910dd5ea1723f43673deeae5036ff..c1ae58bc40c7db5a1010124025b4bfcef5314121 100644
--- a/dynare++/src/dynare_atoms.cpp
+++ b/dynare++/src/dynare_atoms.cpp
@@ -135,22 +135,19 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
 
 	// set parameteres
 	for (unsigned int i = 0; i < atoms.get_params().size(); i++) {
-		try {
+        if (atoms.is_referenced(atoms.get_params()[i])) {
 			const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_params()[i]);
 			for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
 				 it != lmap.end(); ++it) {
 				int t = (*it).second;
 				et.set_nulary(t, paramvals[i]);
 			}
-		} catch (const ogu::Exception& e) {
-			// ignore non-referenced parameters; there is no
-			// lagmap for them
 		}
 	}
 
 	// set endogenous
 	for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) {
-		try {
+        if (atoms.is_referenced(atoms.get_endovars()[outer_i])) {
 			const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_endovars()[outer_i]);
 			for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
 				 it != lmap.end(); ++it) {
@@ -165,15 +162,12 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
 				else
 					et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]);
 			}
-		} catch (const ogu::Exception& e) {
-			// ignore non-referenced endogenous variables; there is no
-			// lagmap for them
 		}
 	}
 
 	// set exogenous
 	for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) {
-		try {
+        if (atoms.is_referenced(atoms.get_exovars()[outer_i])) {
 			const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_exovars()[outer_i]);
 			for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
 				 it != lmap.end(); ++it) {
@@ -184,8 +178,6 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
 					et.set_nulary(t, xx[i]);
 				}
 			}
-		} catch (const ogu::Exception& e) {
-			// ignore non-referenced variables
 		}
 	}
 }