@@ -78,22 +78,6 @@ send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
7878send_program_fatal_error_notification(env, NOTIFICATION_ERROR_FATAL, "Error message");
7979```
8080
81- ## Error Handling
82-
83- ### Standard Pattern
84- ``` cpp
85- try {
86- // Main program logic
87- send_program_finished_notification (env, NOTIFICATION_PROGRAM_FINISH);
88- }catch (ProgramFinishedException&){
89- send_program_finished_notification (env, NOTIFICATION_PROGRAM_FINISH);
90- throw;
91- }catch (std::exception& e){
92- send_program_fatal_error_notification (env, NOTIFICATION_ERROR_FATAL, e.what());
93- throw;
94- }
95- ```
96-
9781## Controller Input
9882
9983### Button Presses
@@ -108,6 +92,45 @@ context.wait_for_all_requests(); // wait for button to finish execution
10892context.wait_for(std::chrono::milliseconds(1000));
10993```
11094
95+ ## Main Program Function Pattern
96+
97+ ### Simplest Program
98+ ``` cpp
99+ void ProgramName::program (SingleSwitchProgramEnvironment& env, ProControllerContext& context){
100+ // button presses and inference routines
101+ }
102+ ```
103+
104+ ## Looping Program with Ability to Recover from Minor Error
105+
106+ ```cpp
107+ while(true){
108+ try{
109+ // Initialization logic
110+
111+ env.update_stats();
112+ send_program_status_notification(env, NOTIFICATION_STATUS_UPDATE);
113+
114+ // Main program logic
115+
116+ send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
117+ }catch(ProgramFinishedException&){ // an exception indicating the program has finished
118+ env.update_stats();
119+ send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
120+ throw;
121+ }catch(ScreenshotException& e){ // an exception indicating an error somewhere in the loop
122+ if(...){ // if we can recover from it
123+ // execute recover logic (usually is restarting the game)
124+ continue;
125+ }
126+ // we cannot recover from the exception. Throw the exception to the higher level to
127+ // trigger fatal error noticiation and cleanup.
128+ throw;
129+ }
130+ }
131+ ```
132+
133+
111134## Program Registration
112135
113136### In GameName_Panels.cpp
0 commit comments