diff --git a/matlab/osr1.m b/matlab/osr1.m
index deba959457292139cede41a4715c3de98c8c3220..a8d3931488fec6d9404d0ad59da51dbd1068ea81 100644
--- a/matlab/osr1.m
+++ b/matlab/osr1.m
@@ -51,7 +51,15 @@ if ~ M_.lead_lag_incidence(M_.maximum_lag+1,:) > 0
 end
 
 if M_.maximum_lead == 0
-    error ('Backward or static model: no point in using OSR') ;
+    error ('OSR: Backward or static model: no point in using OSR') ;
+end
+
+if any(any(isinf(weights)))
+    error ('OSR: At least one of the optim_weights is infinite.') ;
+end
+
+if any(isnan(M_.params(i_params)))
+    error ('OSR: At least one of the initial parameter values for osr_params is NaN') ;
 end
 
 exe =zeros(M_.exo_nbr,1);
@@ -61,6 +69,8 @@ oo_.dr = set_state_space(oo_.dr,M_,options_);
 
 np = size(i_params,1);
 t0 = M_.params(i_params);
+
+
 inv_order_var = oo_.dr.inv_order_var;
 
 H0 = 1e-4*eye(np);
@@ -75,6 +85,12 @@ if info~=0
 else
    fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss);
 end
+if isinf(loss)
+   fprintf('\nOSR: The initial value of the objective function is infinite.\n');
+   fprintf('\nOSR: Check whether the unconditional variance of a target variable is infinite\n');
+   fprintf('\nOSR: due to the presence of a unit root.\n');
+   error('OSR: Initial likelihood is infinite')
+end
 
 %%do actual optimization
 [f,p]=csminwel1('osr_obj',t0,H0,[],crit,nit,options_.gradient_method,options_.gradient_epsilon,i_params,...