(a) No person shall intentionally, knowingly, or recklessly carry on or about the person while inside any building in which judicial proceedings are in progress any weapon prohibited by § 39-17-1302(a), for the purpose of going armed; provided, that if the weapon carried is a firearm, the person is in violation of this section regardless of whether the weapon is carried for the purpose of going armed.
(b) Any person violating subsection (a) commits a Class E felony.
(c) Subsection (a) shall not apply to any person who:

(1) Is in the actual discharge of official duties as a law enforcement officer, or is employed in the army, air force, navy, coast guard or marine service of the United States or any member of the Tennessee national guard in the line of duty and pursuant to military regulations, or is in the actual discharge of official duties as a guard employed by a penal institution, or as a bailiff, marshal or other court officer who has responsibility for protecting persons or property or providing security;
(2) Has been directed by a court to bring the firearm for purposes of providing evidence;
(3) Is in the actual discharge of official duties as a judge, and:

(A) Is authorized to carry a handgun pursuant to § 39-17-1351;
(B) Keeps the handgun concealed at all times when in the discharge of such duties; and
(C) Is vested with judicial powers under § 16-1-101;
(4) Is in the actual discharge of official duties as an elected official of any county or municipality, and:

(A) Is authorized to carry a handgun pursuant to § 39-17-1351; and
(B) Is not in the room in which judicial proceedings are in progress; or
(5) Is in the actual discharge of official duties as the county attorney of any county in this state, and:

(A) Is authorized to carry a handgun pursuant to § 39-17-1351; and
(B) Is not in the room in which judicial proceedings are in progress.