This phrase is usually used when bad things happen. For instance...
Person1: I think we lost all our money in the casino... Person2: Aw, crap!