Can I put a try-catch in GUI initialization code?

조회 수: 2 (최근 30일)
David K
David K 2017년 4월 6일
답변: Randy Acheson 2017년 4월 10일
I am building a GUI using GUIDE in 2016a which I will be compiling and deploying. I want to try to do some global error handling, and it occurs to me that any command given to the GUI first goes through the main initialization code before going to the specific Callback function. My thought was to put a try-catch block around the calls to gui_mainfcn. What's making me hesitate is that the code is bookended by some big old warnings:
% Begin initialization code - DO NOT EDIT
... initialization code here ...
% End initialization code - DO NOT EDIT
Could I break something by putting a try-catch block inside this initialization section? Is there a better way to attempt global error handling for a single GUI?

채택된 답변

Randy Acheson
Randy Acheson 2017년 4월 10일
If you are looking to do global error handling, this may be an effective way. There could be some issues with catching errors from callbacks, as detailed in this post:
https://www.mathworks.com/matlabcentral/answers/90309-is-using-a-try-catch-around-gui_mainfcn-a-bad-idea?s_tid=answers_rc1-1_p1_Topic

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by