| 1 |
function [stage, errorHasOccurred] = errorHandler(e) |
| 2 |
% common error handler code: save and print to console |
| 3 |
errorHasOccurred = true; |
| 4 |
stage = emptyStage(); |
| 5 |
stage.message = format_error_message(e); |
| 6 |
stage.error = errorHasOccurred; |
| 7 |
|
| 8 |
disp_error_message(stage.message); |
| 9 |
end |
| 10 |
% ============================================================================== |
| 11 |
function msg = format_error_message(e) |
| 12 |
msg = ''; |
| 13 |
if ~isempty(e.message) |
| 14 |
msg = sprintf('%serror: %s\n', msg, e.message); |
| 15 |
end |
| 16 |
if ~isempty(e.identifier) |
| 17 |
if strfind(lower(e.identifier),'testmatlab2tikz:') |
| 18 |
% When "errors" occur in the test framework, i.e. a hash mismatch |
| 19 |
% or no hash provided, there is no need to be very verbose. |
| 20 |
% So we don't return the msgid and the stack trace in those cases! |
| 21 |
return % only return the message |
| 22 |
end |
| 23 |
msg = sprintf('%serror: %s\n', msg, e.identifier); |
| 24 |
end |
| 25 |
if ~isempty(e.stack) |
| 26 |
msg = sprintf('%serror: called from:\n', msg); |
| 27 |
for ee = e.stack(:)' |
| 28 |
msg = sprintf('%serror: %s at line %d, in function %s\n', ... |
| 29 |
msg, ee.file, ee.line, ee.name); |
| 30 |
end |
| 31 |
end |
| 32 |
end |
| 33 |
% ============================================================================== |
| 34 |
function disp_error_message(msg) |
| 35 |
stderr = 2; |
| 36 |
% The error message should not contain any more escape sequences and |
| 37 |
% hence can be output literally to stderr. |
| 38 |
|
| 39 |
fprintf(stderr, '%s', msg); |
| 40 |
end |
| 41 |
% ============================================================================== |