Suppress line number display in error message
26 views (last 30 days)
Is there a way to suppress the line number display when using the error command? For example, the following statement in a function: error('ERROR: I do not like argument %s',arg); displays an extra line showing where the error line occurred. ??? Error using ==> (file name) at (line number) ERROR: I do not like argument (argument) Can one stop the first line (with three question marks) from being generated? I want to stop execution (regardless of how deeply this function is buried), but the end user doesn't need to know where the error was generated.
Image Analyst on 3 Nov 2012
Yes. Use try/catch and spit out whatever error message you want:
% Some code that throws an exception....
errorMessage = sprintf('Error in function BlahSnafuFubar().\n\nError Message:\n%s', ME.message);
Daniel Shub on 5 Nov 2012
Edited: Daniel Shub on 5 Nov 2012
In your exact use case, where you only supply an error message and no identifier, I don't think you can. If you are willing to provide an identifier than you can do something like
throwAsCaller(MException(MSGID, 'ERROR: I do not like argument %s', arg))
This will move you one step up in the stack. In order to make it all the way to the top you would need
at each level.
Arthur on 6 Nov 2012
Use getReport instead. For instance
Daniel Shub on 6 Nov 2012
I will try this as a new answer. Just wrap everything (or almost everything) in a try-catch...
function varargout = reader(varargin)
errMsg = (inputchecker(varargin));
varargout = p_reader(varargin);
errMsg = disectME(ME);
where inputchecker checks the inputs as best as possible, p_reader is your current reader function, and disectME deals with the different errors that may happen in p_reader.