How can I display a script-called function's error message without pausing the script?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Daniel Toth
il 8 Giu 2018
Commentato: methaq ali
il 28 Lug 2018
I am writing a script for documentation purposes to "verify" a function I have written. I would like to demonstrate in the script what the function's error messages look like without stopping the script. I'm thinking of using a "try-catch" statement to not pause the script when an error is returned, but I am not sure how to display the function's error message in the "catch" part of the statement.
My function's error-message code has a specific format (i.e. it displays the error between lines of asterisks) and looks like this (for example):
if input<0
msg = 'Error: Input must be greater than 0.';
error('EXAMPLE:operational', 'Sign Error\n%s\n%s\n%s\n', ...
repmat('*',1,82), msg, repmat('*',1,82));
end
I am thinking of calling the function in my verification script like this:
try
test = myFun(-5); %Test negative input
catch
%What do I put here so that the script displays the function's error
%message to the command window?
end
It may be that I must simply put 'disp('the function returned an error')' in the catch statement, but it would be very nice to display the exact error message for documentation purposes. Thank you for your time!
0 Commenti
Risposta accettata
Walter Roberson
il 8 Giu 2018
try
test = myFun(-5); %Test negative input
catch ME
disp(ME.message)
end
Più risposte (1)
methaq ali
il 28 Lug 2018
Modificato: Walter Roberson
il 28 Lug 2018
when writing the statement
net=newff(p,t,3,('logsig' 'purelin'));
|(this line under letter p)
the following message appear:
Error: Unexpected MATLAB expression.
Can any one help me to locate the error?
2 Commenti
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!