How to use "error " in code in function
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Florian Bidaud
2023-8-23
编辑:Florian Bidaud
2023-8-23
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!