Skip Error Message and Continue with the M-File

43 Ansichten (letzte 30 Tage)
Newuser
Newuser am 17 Jun. 2011
Kommentiert: Marcel am 17 Nov. 2022
Hello dear Friends,
does someone know how to have a m-file to continue after an error message is returned !?
I've a file that retrives info from the internet (data, etc.). Sometimes (randomly) an internet connection problem results (error 111) and matlab stops to execute the m-file algo! Since this files connects to more than 5000 web pages (one per time) it is possible that a connection error is returned in matlab.
I simply want the program to resume the operations specified in the m-file.
does someone know how to do this?
thank you for your help ...
  4 Kommentare
Javier Munoz
Javier Munoz am 15 Mai 2017
I need to omit an error that appear in a "msgbox"Walter,
Walter Roberson
Walter Roberson am 15 Mai 2017
Create your own function msgbox and place it earlier in the path than MATLAB's version:
function fig = msgbox(varargin)
if nargout > 0
fig = gobjects(0);
end
Note: the above is valid for R2014b and later only.
This will likely interfere with messages that you want kept. so a much better strategy would be to either comment out the calls you do not want or else put them inside an "if" condition that allows you to choose whether to display them or not.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Arturo Moncada-Torres
Arturo Moncada-Torres am 17 Jun. 2011
Completing Gerd's answer, I would include the catch statement. The catch executes everytime an error is encountered in the try block, so maybe not display an error message that stops the execution, but maybe a message in console to know that something went wrong (execution will continue anyway):
try
% Code to be executed goes here.
catch
disp('An error occurred while retrieving information from the internet.');
disp('Execution will continue.');
end
  2 Kommentare
Yu
Yu am 14 Nov. 2013
but the statement between the catch and end never exectes!!!!
It only check whether the statement between catch and end is processable!!!
What if i want to execute one statement between try and catch, if errors happens bewtween thoses statements, the error will be ignored and the statement between the catch and end will be executed!!!?
Marcel
Marcel am 17 Nov. 2022
Excuse me what? You know how a try-catch block works?
A catch -block contains statements that specify what to do if an exception is
thrown in the try -block. If any statement within the try -block (or in a function
called from within the try -block) throws an exception, control is immediately shifted
to the catch -block

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Gerd
Gerd am 17 Jun. 2011
Hi,
just use the try command on the weboperation.
try
%commands to be executed
end
If you do have a problem between the try block you still can continue in your m-file
Gerd

Ahmadreza Eslami
Ahmadreza Eslami am 27 Apr. 2022
The code that you are going to execute has an erronous line(s). In case of error, part under try will stop due to the error but the catch part will continue which the second part of your code after error.
% Your code part one
try
% your code
% Error
catch
% Your code part two
end

Kategorien

Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by