How can I suppresses the display of error messages with urlwrite ?

>> url_img
url_img =
http://satelite.cptec.inpe.br/repositorio9/goes12_met9/goes12_met9_web/ams_afc_alta_jpg/2010/03/S11868143_201003010600.jpg
>> [filestr,status] = urlwrite(url_img);
??? Error using ==> urlwrite at 39
Not enough input arguments.

 Réponse acceptée

Mohammad Abouali
Mohammad Abouali le 20 Oct 2014
Modifié(e) : Mohammad Abouali le 20 Oct 2014
I think the best is to fix your command.
the minimum usage of urlwrite is:
[filestr,status]=urlwrite(URL,filename)
so, it seems that filename=S11868143_201003010600.jpg and URL=http://satelite.cptec.inpe.br/repositorio9/goes12_met9/goes12_met9_web/ams_afc_alta_jpg/2010/03/
Then check status to see if you got any error.
By the way, that file on that URL seems not to be available anyhow.

Plus de réponses (1)

try
[filestr,status] = urlwrite(url_img);
catch me
% handle the error
end

7 commentaires

It runs, but I need to understand what it means, Could you teach me ? And, Why the filestr and status don't show me nothing ?
I can do this without the function try ?
per isakson
per isakson le 20 Oct 2014
Modifié(e) : per isakson le 20 Oct 2014
you shouldn't use try/catch to get matlab syntax error. fix your command first. This is an error arising from wrong usage of urlwrite.
per isakson
per isakson le 20 Oct 2014
Modifié(e) : per isakson le 20 Oct 2014
"you shouldn't use try/catch" &nbsp That's depend on the context.
It's appropriate if you want to
  • loop over many URLs and write the error messages to a log file.
  • present the error in a GUI.
Mohammad Abouali
Mohammad Abouali le 20 Oct 2014
Modifié(e) : Mohammad Abouali le 20 Oct 2014
but the problem is not a runtime error. It is a syntax error.
Try/catch is there to catch a possible runtime error during your code execution, so that instead of crashing the code, handling it in such a way that the code can continue such as representing the error in those two cases that you said.
But here you have a syntax error. urlwrite requires at least two input parameters. Providing one input argument is always an error. Regardless of your runtime state, that line always throughs an error (due to syntax error) and goes to the catch section. So, first the command syntax needs to be fixed.
And my comment wasn't " you shouldn't use try/catch ". It was "you shouldn't use try/catch to get matlab syntax error." Read the whole thing and when you quote someone, you should quote properly. Of course you can use the try/catch, but not to catch your syntax errors, but the runtime errors.
Given the title of the question, my answer was correct.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by