Bonjour à tous,
J'aimerais comprendre l'utilisation de l'ensemble try/catch. Enfin, j'en comprends le sens mais je ne sais pas quoi mettre comme "exception" en face du catch. Si on regarde la doc :
Pour comprendre, j'aimerais que vous me disiez quelle "exception" je dois indiquer lorsque j'utilise le try/catch pour vider le buffer d'un port série. Mon code est celui-ci :Syntax
try
statements
catch exception
statements
end
Description
try and catch blocks allow you to override the default error behavior for a set of program statements. If any statement in a try block generates an error, program control goes immediately to the catch block, which contains your error handling statements.
exception is an optional MException object input to the catch block that allows you to identify the error.
Both try and catch blocks can contain nested try/catch statements
On peut éviter d'utiliser le try/catch mais je vais me répèter : Je veux comprendre comment définir l'exception et ne plus avoir le catch de souligné.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 try vidange=fread(microchip_obj,microchip_obj.BytesAvailable); % on vide le buffer catch vidange=0; end
Cordialement,
Christophe Halgand
Partager