How to use "error " in code in function

3 views (last 30 days)
aldo
aldo on 23 Aug 2023
Commented: aldo on 23 Aug 2023
I have a code that works perfectly..
i try to use error in a condition:(it's use in a funcion called in app designer)
if true
error('Error. \n groupRank contiene ripetizione elementi'); %%check per scurezza..per come ho impostato la logica del rank in groupRank ci deve essere 1 solo sistema nei gruppi di rank!
return;
end
and i receive this error:
Error using Calcola_FiltroRaking_Struct
Error. \n groupRank contiene ripetizione elementi
Error in Predator_Filtri_Preset_Struct (line 96)
filtroRanking=Calcola_FiltroRaking_Struct(Sis,Eq,Preset,contract);
Error in PredatorBEGIN_AppDesign_Struct (line 94)
Eq=Predator_Filtri_Preset_Struct(Sis,Eq,Preset); % MI CREA IL Eq.Filtri.filtro_Finale dalla curva base..(usa il filtro_oos PER IL RANKING!!)
Error in Predy/AvvioPredatorButtonPushed (line 583)
[app.eq,app.sis]=PredatorBEGIN_AppDesign_Struct(app.setting,app.preset);
i dont understand the other error (line 96..line 94) what kind of error is
I don't receive ani information about it
I can't to post code...
the code is very elaborate and they are functions called in the app designer
I would like when the error occurs to exit the "Main" program completely but I see that "return" does not do this

Answers (1)

Florian Bidaud
Florian Bidaud on 23 Aug 2023
Edited: Florian Bidaud on 23 Aug 2023
It is just telling you where the error occurs in each subfunction.
You can't have a return after the 'error' because error WILL error and then stop the code.
Do you really need the error ?
You could just remove it so it would leave the function with the return,
And then throw an error.
For example:
% your code
output = yourFunction(inputs)
if strcmp(output,'error')
error('Error. \n groupRank contiene ripetizione elementi')
end
function output = yourFunction(inputs)
% your function code
if true
output = 'error';
return;
end
end
  1 Comment
aldo
aldo on 23 Aug 2023
in case of check the condition "X" i want to use from main code

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!