ABSTRACT

The very first step is to surround your code with try-catch statements. The function of this will be to ‘try’ your script, but then execute some other code if any error or fatal bug is encountered. Without this, if your program fails after you run it, you may be

stuck on a black screen because the code does not have a chance to reach your ‘q’ escape command or the Screen('Close') command. This black screen can be very difficult to get rid of at times, and might even frustrate you enough to force a reboot on your computer. Your solution is try-catch. At the very top of your script, immediately after your ‘close all’ command, type the word try, then indent all of the rest of your script (an easy way to do this is to highlight everything, then use cmd + ] to indent the code on a Mac, or ctrl + ] on a Windows system). The script should look like it does in Figure 7.1 at the top.