Solved by ptrblck in post #2 
              
              
                I think checking for an empty output before applying the mean operation sounds like a simple and valid solution. 
What kind of solution are you looking for and would the check not work for you?