LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
line_error.m
1function line_error(caller, msg)
2%LINE_ERROR Display a plain-text error message with file and line info.
3%
4% LINE_ERROR(CALLER, MSG) throws an error with CALLER's name and message,
5% including the source file and line number, in plain text (no hyperlink).
6
7% Copyright (c) 2012-2026, Imperial College London
8% All rights reserved.
9
10try
11 msg = strrep(msg, '\n', ''); % Strip out literal '\n' if present
12 stack = dbstack;
13
14 if numel(stack) >= 2
15 lineNum = stack(2).line;
16 else
17 lineNum = 1;
18 end
19
20 filePath = which(caller);
21 if isempty(filePath)
22 filePath = caller;
23 end
24
25 errStr = sprintf('[%s.m @ line %d] %s', caller, lineNum, msg);
26 error(errStr);
27
28catch ME
29 throwAsCaller(ME);
30end
31end