A convicted felon was sentenced to eight years in prison on Tuesday for illegally possessing a handgun he used to intimidate his ex-girlfriend.

Joseph Riley, a 44-year-old Chicago resident, had a Sig Sauer P229 .40-caliber pistol on at least four occasions in 2015, according to a statement from the U.S. attorney’s office. On one occasion, he took out the gun and used it to intimidate his ex-girlfriend.

Riley had prior felony convictions, including two felonies for illegally possessing firearms, so he could not lawfully have the gun, according to the U.S. attorney’s office. He pleaded guilty earlier this year to one count of illegal possession of a firearm by a felon.

“Each instance in which the defendant possessed the gun was dangerous and threatening,” Assistant U.S. Attorney Matthew L. Kutcher said in a sentencing memorandum.