LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
line_error.m
1function line_error(caller, msg, varargin)
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
5% message, including the source file and line number, in plain text (no
6% hyperlink). Extra arguments are passed to sprintf to format MSG.
7
8% Copyright (c) 2012-2026, Imperial College London
9% All rights reserved.
10
11if coder.target('MATLAB')
12 if ~isempty(varargin)
13 msg = sprintf(msg, varargin{:});
14 end
15 try
16 msg = strrep(msg, '\n', ''); % Strip out literal '\n' if present
17 stack = dbstack;
18
19 if numel(stack) >= 2
20 lineNum = stack(2).line;
21 else
22 lineNum = 1;
23 end
24
25 filePath = which(caller);
26 if isempty(filePath)
27 filePath = caller;
28 end
29
30 errStr = sprintf('[%s.m @ line %d] %s', caller, lineNum, msg);
31 error(errStr);
32
33 catch ME
34 throwAsCaller(ME);
35 end
36else
37 error('%s: %s', caller, msg);
38end
39end