How to use "error " in code in function

3 visualizaciones (últimos 30 días)
aldo
aldo el 23 de Ag. de 2023
Comentada: aldo el 23 de Ag. de 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

Respuestas (1)

Florian Bidaud
Florian Bidaud el 23 de Ag. de 2023
Editada: Florian Bidaud el 23 de Ag. de 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 comentario
aldo
aldo el 23 de Ag. de 2023
in case of check the condition "X" i want to use from main code

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by