A U.S. appeals court in San Francisco has upheld a law that prohibits people in the country illegally from possessing guns.

A three-judge panel of the 9th U.S. Circuit Court of Appeals ruled unanimously Tuesday that the law does not violate the Second Amendment right to bear arms.

The judges said immigrants who are armed and in the U.S. illegally could pose a threat to officers trying to remove them.

They also said those immigrants are hard to monitor and have already shown they don't respect the law.

The ruling came in the case of Victor Manuel Torres, a Mexican national who was convicted after officers found a revolver in his backpack.

Adam Gasner, an attorney for Torres, said he was studying the opinion and has not yet decided whether to appeal.