try
    screens = Screen('Screens');
    whichscreen = max(screens);
    [myscreen, rect] = Screen('OpenWindow', whichscreen, [0, 255, 0]);
    square_size = [0, 0, 400, 400];
    square_rect = CenterRect(square_size, rect);
    Screen('FillRect', myscreen, [255, 0, 0], square_size);
    Screen('Flip', myscreen);
    KbWait;
    Screen('CloseAll');
catch
    screen('CloseAll')
    rethrow(lasterror)
end