Unless you were a witness it sounds a complicated thing. If the car in front of you brakes then you should be at a sufficient distance behind that you can brake safely. I've been involved in a few accidents where a car behind has run into me and also where i've run into a car in front of me. Its not usual that the car behind would swerve off the road to avoid me