In a criminal case, any defense or objection based upon defects in the institution of the prosecution or in the complaint or indictment, other than a failure to show jurisdiction in the court or to charge an offense, shall only be raised prior to trial and only by a motion in conformity with the requirements of the Massachusetts Rules of Criminal Procedure. The failure to raise any such defense or objection by motion prior to trial shall constitute a waiver thereof, but a judge or special magistrate may, for cause shown, grant relief from such waiver. A defense or objection based upon a failure to show jurisdiction in the court or the failure to charge an offense may be raised by motion to dismiss prior to trial, but shall be noticed by the court at any time.
Mass. Gen. Laws ch. 277, § 47A