First, the animals used in filming are trained professionals, but as we all know animals; like people can be wild and unpredictable, which is why they have personal trainers usually ones that work with the same animals going from set to set (They are not actors but animal trainers). NOTE it is required by law to have a representative of the American Humane Society on set at all times.
Now there are different ways to go about with animals on set. In some movies live animals are used for far shots or shots with out actors. Shots with actors are usually quick takes because of the lights and chaos on set (and there are very few in most cases). Take a look at the Hangover 1, the lion scene in the hotel was a real lion. Other shots can be done with CGI.
Life of Pi is a good example of animals and CGI.
Now before computers film makers rely on the power of cinematography. the shot may have the actor to the right and the animal a safe distance away but with a little camera trickery; on screen it looks like they are next to each other. other cases are the fact that they use real live animals and just took the risk.
TAKE A LOOK at the film ROAR 1981
In other cases they rely on animatronics.
Jaw, Jurassic park is a good examples of that.
The hole idea is to come up with the most real life image you can on the budget you are given with the technology and knowledge you possess.
Today CGI has become the best way to handle this because of safety issues and time restraints.