diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index ae9babbc24c3abd21517cec0d58853b9a51d978d..233a4a4cea6b7c7ccda9c63ced0b48eb428e464c 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -708,6 +708,12 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
                                                            DynareOptions.rescale_prediction_error_covariance, ...
                                                            DynareOptions.presample, ...
                                                            T,Q,R,H,Z,mm,pp,rr,Zflag,diffuse_periods, occbin_);
+            if occbin_.status && isinf(LIK)
+                fval = Inf;
+                info(1) = 320;
+                exit_flag = 0;
+                return
+            end
         end
     end
     if analytic_derivation
diff --git a/matlab/get_error_message.m b/matlab/get_error_message.m
index f59cac2842c4e743c84c2276469963bb6b10a0eb..1013184d69aeabf1c1434238082a4a718742bfee 100644
--- a/matlab/get_error_message.m
+++ b/matlab/get_error_message.m
@@ -188,6 +188,8 @@ switch info(1)
         message = 'Occbin: Simulation did not converge, increase maxit or check_ahead_periods.';        
     case 312
         message = 'Occbin: Constraint(s) are binding at the end of the sample.';        
+    case 320
+        message = 'Piecewise linear Kalman filter: There was a problem in obtaining the likelihood.';        
     otherwise
         message = 'This case shouldn''t happen. Contact the authors of Dynare';
 end
\ No newline at end of file