필터 지우기
필터 지우기

why does try-catch command fail sometime?

조회 수: 1 (최근 30일)
yvette-hyq
yvette-hyq 2013년 1월 1일
I have been using try-catch command in my loop for solving economic model using Dynare. It does the job normally, but sometimes it doesn't. For example, the following error happens all the time, and the try-catch command catches the error and moves on to next iteration. But yesterday, it stops the whole program.
'Blanchard Kahn conditions are not satisfied: indeterminacy.
the code I am using is:
try
dynare US_EAcoordination;
catch err
load file_name;
load(model_type);
tem_iteration = strcat('iteration_',num2str(iteration));
estimation.(char(tem_iteration)).errmag = err.message;
save(model_type,'estimation','-append');
end
Thanks so much...
  댓글 수: 1
Matt J
Matt J 2013년 1월 1일
편집: Matt J 2013년 1월 1일
How do you know the try/catch is responsible for the program stopping?

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2013년 1월 1일
I don't see any loop there to cause iterations.
If that code is inside a loop, then the loop should continue after it finishes with the catch, in which case it will go into dynare again (unless you were already on the last iteration).
If that is your whole script, then that script will be done after the catch.
  댓글 수: 1
Image Analyst
Image Analyst 2013년 1월 2일
Commenting on your "Answer" below:
It must hit an error outside of that try block. Use "dbstop if error" to have it stop at that line of code so you can find out where it is.

댓글을 달려면 로그인하십시오.


yvette-hyq
yvette-hyq 2013년 1월 2일
Thanks.
This code is within iterations using Simulated Annealing algorithm. I am afraid it is too long to be shown here.
And yes, after catching errors, normally it continues to next iteration and runs dynare again when it comes to 'try'.
My question is, however, why would it break out from whole algorithm when it catches error sometime?
It stops whole algorithm at 148th iteration, with an error happened lots of times before. I just don't get it.
Thanks again.

카테고리

Help CenterFile Exchange에서 Platform and License에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by