From fd54a514d6ac311f7bd63e8a06525e9295ddbb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Mon, 18 Nov 2024 11:44:31 +0100 Subject: [PATCH] =?UTF-8?q?Simplification=20using=20the=20=E2=80=9Ccatch?= =?UTF-8?q?=20VALUE=E2=80=9D=20syntax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It has been available in Octave for a long time. --- matlab/estimation/dynare_estimation_1.m | 3 +-- matlab/estimation/dynare_estimation_init.m | 5 ++--- matlab/parallel/fParallel.m | 5 ++--- matlab/parallel/slaveParallel.m | 7 +++---- matlab/stochastic_solver/AIM_first_order_solver.m | 5 ++--- matlab/utilities/tests | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/matlab/estimation/dynare_estimation_1.m b/matlab/estimation/dynare_estimation_1.m index a2e9ffd8c..6e2bd2bee 100644 --- a/matlab/estimation/dynare_estimation_1.m +++ b/matlab/estimation/dynare_estimation_1.m @@ -167,8 +167,7 @@ end try oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,bounds,oo_); -catch % if check fails, provide info on using calibration if present - e = lasterror(); +catch e % if check fails, provide info on using calibration if present if estim_params_.full_calibration_detected %calibrated model present and no explicit starting values skipline(1); fprintf('ESTIMATION_CHECKS: There was an error in computing the likelihood for initial parameter values.\n') diff --git a/matlab/estimation/dynare_estimation_init.m b/matlab/estimation/dynare_estimation_init.m index 13c1c9e83..f025548f5 100644 --- a/matlab/estimation/dynare_estimation_init.m +++ b/matlab/estimation/dynare_estimation_init.m @@ -30,7 +30,7 @@ function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, % SPECIAL REQUIREMENTS % none -% Copyright © 2003-2023 Dynare Team +% Copyright © 2003-2024 Dynare Team % % This file is part of Dynare. % @@ -204,8 +204,7 @@ if ~isempty(estim_params_) && ~(all(strcmp(fieldnames(estim_params_),'full_calib if options_.use_calibration_initialization try check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_) - catch - e = lasterror(); + catch e fprintf('Cannot use parameter values from calibration as they violate the prior bounds.') rethrow(e); end diff --git a/matlab/parallel/fParallel.m b/matlab/parallel/fParallel.m index 54dec1cc6..0ff7db9de 100644 --- a/matlab/parallel/fParallel.m +++ b/matlab/parallel/fParallel.m @@ -18,7 +18,7 @@ function fParallel(fblck,nblck,whoiam,ThisMatlab,fname) % OUTPUTS % None % -% Copyright © 2006-2017 Dynare Team +% Copyright © 2006-2024 Dynare Team % % This file is part of Dynare. % @@ -92,8 +92,7 @@ try end disp(['fParallel ',int2str(whoiam),' completed.']) -catch - theerror = lasterror; +catch theerror if strfind(theerror.message,'Master asked to break the job') fOutputVar.message = theerror; save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ) diff --git a/matlab/parallel/slaveParallel.m b/matlab/parallel/slaveParallel.m index 1d094e6f0..8d463fee7 100644 --- a/matlab/parallel/slaveParallel.m +++ b/matlab/parallel/slaveParallel.m @@ -15,7 +15,7 @@ function slaveParallel(whoiam,ThisMatlab) % OUTPUTS % None -% Copyright © 2006-2017 Dynare Team +% Copyright © 2006-2024 Dynare Team % % This file is part of Dynare. % @@ -143,8 +143,7 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in disp(['Job ',fname,' on CPU ',int2str(whoiam),' completed.']); t0 =clock; % Re-set waiting time of 20 mins - catch - theerror = lasterror; + catch theerror if strfind(theerror.message,'Master asked to break the job') disp(['Job ',fname,' on CPU ',int2str(whoiam),' broken from master.']); fOutputVar.message = theerror; @@ -152,7 +151,7 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in delete(['P_',fname,'_',int2str(whoiam),'End.txt']); else disp(['Job ',fname,' on CPU ',int2str(whoiam),' crashed.']); - fOutputVar.error = lasterror; + fOutputVar.error = theerror; save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ); waitbarString = fOutputVar.error.message; if Parallel(ThisMatlab).Local diff --git a/matlab/stochastic_solver/AIM_first_order_solver.m b/matlab/stochastic_solver/AIM_first_order_solver.m index 067d554a3..cc664655a 100644 --- a/matlab/stochastic_solver/AIM_first_order_solver.m +++ b/matlab/stochastic_solver/AIM_first_order_solver.m @@ -100,10 +100,9 @@ uprbnd = 1 + 1.e-6; %allow unit roots try % try to run AIM [bb, rts, ~, ~, ~, ~, aimcode] = SPAmalg(g1(:, 1:3*M_.endo_nbr), neq, 1, 1, condn, uprbnd); -catch - err = lasterror; +catch err disp(['Dynare AIM Solver error:' sprintf('%s; ID:%s',err.message, err.identifier)]); - rethrow(lasterror); + rethrow(err); end if aimcode==1 %if OK dr.ghx = bb(dr.order_var, dr.order_var(M_.nstatic+(1:M_.nspred))); diff --git a/matlab/utilities/tests b/matlab/utilities/tests index c5ce76453..b484b6e62 160000 --- a/matlab/utilities/tests +++ b/matlab/utilities/tests @@ -1 +1 @@ -Subproject commit c5ce7645386c6d2e42a018957e245caa3dc05fde +Subproject commit b484b6e625a8dbca209afb884af2125a0368775c -- GitLab