diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index ff5246495ead90144ab7c9df2628318881f14ae8..10f594db02d9e5e55a597d0600fae999bcf4c169 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 e1a4523b2b825abb445d5d0afcdb5738beb3e4a8..0b700ead6eb743b2cd1bd43f464a62bf74dbec3c 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