There are a few exercises that can give you a hernia. Anything that has you lifting weight while not in a prone position would be good candidates for causing one.
Lifting weights can definitely give you a hernia, especially if you are not lifting them correctly, or placing them back down on the floor in the appropriate position.
It is better to do aerobic type exercise carried out at a steady rate for long periods, which doesn't involve straining. Swimming and static cycling is also good.