diff --git a/src/mtest.m b/src/mtest.m
index 703375ce6fa330026c91f7833bd7a31b16b4b905..2db273a790e7ed3e283adecbaf20f07247a76def 100644
--- a/src/mtest.m
+++ b/src/mtest.m
@@ -24,7 +24,7 @@ function [check, info] = mtest(fname, fpath)
 %  - If two input arguments are provided, fname is the base name of the targeted
 %    matlab routine and fpath is the path to this routine.
 
-% Copyright © 2013-2023 Dynare Team
+% Copyright © 2013-2024 Dynare Team
 %
 % This file is part of Dynare (m-unit-tests module).
 %
@@ -102,12 +102,10 @@ for i=1:nn
         fprintf(tid,str);
     end
     fprintf(tid,'LOG = NaN;\n');
+    fprintf(tid,'catch exception\n');
     if isoctave
-        fprintf(tid,'catch\n');
-        fprintf(tid,'exception = lasterror;\n');
         fprintf(tid, 'LOG = ''%s'';\n','The Log output is not available with Octave!');
     else
-        fprintf(tid,'catch exception\n');
         fprintf(tid,'LOG = getReport(exception,''extended'');\n');
     end
     fprintf(tid,'T = NaN;\n');