Catch terminal's error message
Show older comments
I have a long script executed remotely and would like to capture any error in a log file. I would prefer not to write several try/catch statements, and would rather write a single try/catch around the entire function, and record the exact error, with a line number. But I can't find a tool to capture this.
Even in this simple example, I cannot capture the error message, and the program does not fail gracefully:
try
1=0;
catch ME
disp(ME.identifier)
end
The terminal says
Error: File: test.m Line: 2 Column 6
Incorrect use of '=' operator. To assign a value...
It is this message that I want saved and directed to a file. Can it be done?
Accepted Answer
More Answers (1)
Walter Roberson
on 15 May 2018
0 votes
No, in all modern MATLAB versions, the file is completely parsed before any of it is executed. You would need to have the try/catch in the calling code.
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!