
646 N.W.2d 412 (2002)
Shirley Ann SMITH, Individually and as Parent and Next Friend of Levi Raymond Smith, a Minor, Appellant,
v.
Raymond Francis SMITH, Appellee.
No. 00-1799.
Supreme Court of Iowa.
June 12, 2002.
Rehearing Denied July 16, 2002.
*413 James C. Larew of Larew Law Office, Iowa City, for appellant.
J. Michael Weston and Brenda K. Wallrichs of Moyer & Bergman, P.L.C., Cedar Rapids, for appellee.
LARSON, Justice.
Shirley Smith, on behalf of her minor son, Levi Smith, sued the child's father, defendant Raymond Smith, for negligent infliction of emotional distress when Levi witnessed the events surrounding the death of his younger brother, Eli. The child died as a result of the defendant backing over him with a van. The district court concluded it had no subject matter jurisdiction, based on parental immunity, and dismissed the case. We reverse and remand for further proceedings.

I. Facts and Prior Proceedings.

The plaintiff filed this suit against Raymond Smith and an insurer not involved in this appeal on July 31, 1997. On January 16, 1998, the court set pretrial deadlines. Pleadings were to be closed on November 30, 1998, and dispositive motions were to be filed by December 7, 1998. The plaintiff filed an amendment to her petition on June 11, 1998. The defendant filed his answer on August 6, 1998, but did not assert the defense of parental immunity or subject matter jurisdiction, which ultimately were the bases for the court's dismissal of the plaintiff's case. On November 18, 1998, the plaintiff filed a second amendment to her petition. The defendant answered the second amended petition on November 24, 1998. Again, the defendant did not raise the issues of subject matter jurisdiction or parental immunity.
The court held a pretrial conference on January 5, 1999, and set a trial date of January 20, 1999. All dispositive motions were to be ruled on prior to trial, but Judge Fahey said he was too busy to rule on motions not at issue here, and sua sponte continued the trial without setting a new trial date. Some of the pending motions were ruled on approximately four months later, and some were ruled on approximately nine months later. The court ordered another pretrial conference for March 15, 1999, but no trial date was set. On August 25, 1999, the court held a pretrial conference and set this aspect of the case for trial on June 27, 2000, and remaining claims for October 3, 2000.
*414 The trial commenced on June 27, 2000, but was abruptly halted when the court ordered a mistrial based on the plaintiff's mentioning in her opening statement that there would be evidence of the defendant's intoxication. The court reset the case for October 3, 2000. On September 29, 2000, just five days before the trial, the defendant's attorney filed a brief in which he argued, for the first time, that the defendant was entitled to parental immunity under Wagner v. Smith, 340 N.W.2d 255 (Iowa 1983). The brief contended an earlier case, Turner v. Turner, 304 N.W.2d 786 (Iowa 1981), which had rejected parental immunity, was inapplicable as a matter of law.
The plaintiff responded:
Plaintiff objects, in the strongest possible terms, to Defendant's attempt to file a dispositive motion on the eve of trial, well after all deadlines governing such a filing have lapsed. Such a method of proceeding denies the parties and the Court the opportunity to consider the motion carefullyif it deserves such consideration.
Plaintiff also notes the very difficult position in which Defendant's filing places the parties, waiting until all motions in limine have been filed, heard by the Court, and ruled upon. This case had been on record for more than three years, during all of which time Defendant denied liability for his actions on October 15, 1995....
On October 3, 2000, the parties arrived at the courthouse for trial. As the jury panel gathered, but before jury selection commenced, the court called the attorneys into chambers. The discussion focused on the issues raised in the defendant's recently filed brief. In response to the court's concern that no motion was pending before it concerning dismissal, the defendant's attorney orally moved that the case be dismissed. The district court granted the motion, dismissed the case, assessed costs to the plaintiff, and sent the jurors home. On October 30, 2000, Judge Fahey issued a written "Judgment of Dismissal" in which the earlier oral ruling was confirmed. The plaintiff appealed.

II. The Subject Matter Jurisdiction Argument.

The district court rationalized its dismissal at the time of trial on the basis it was a matter of subject matter jurisdiction, which may be raised at any time. See Iowa Coal Mining Co. v. Monroe County, 555 N.W.2d 418, 428 (Iowa 1996). The only basis for characterizing the defendant's motion as a challenge to subject matter jurisdiction was the plaintiff's passing reference to it as such in her response to the defendant's brief. It is clear that the defendant's motion is not a challenge to subject matter jurisdiction. Subject matter jurisdiction refers to the power of the court to hear and determine cases of the general class to which the proceeding in question belongs, not merely the particular case occupying the court's attention. Cargill, Inc. v. Conley, 620 N.W.2d 496, 501 (Iowa 2000); Powell v. Khodari-Intergreen Co., 303 N.W.2d 171, 173 (Iowa 1981).
The defendant "is certainly not contending and cannot contend that the district court lacked authority to hear the type of cases to which this proceeding belongs." Iowa Coal, 555 N.W.2d at 428. That is so because "[s]ubject matter jurisdiction is conferred by constitutional or statutory power," Hutcheson v. Iowa Dist. Ct., 480 N.W.2d 260, 263 (Iowa 1992), and the defendant does not argue that tort cases by children against their parents are beyond the statutory or constitutional power of the district court to entertain. Moreover, "[s]ubject matter jurisdiction is not *415 dependent on whether the petition has established a meritorious claim." Powell, 303 N.W.2d at 174. The defendant's attack on the plaintiff's claim is clearly not one concerning the power of the court to hear such a claim, and thus is not a motion challenging subject matter jurisdiction. Because it is not a matter of subject matter jurisdiction that is attacked, our procedural rules for such challenges must be observed, particularly with respect to timeliness of the filings.
III. Waiver for Failure to Plead an Affirmative Defense.
Under Iowa Rule of Civil Procedure 88 (recently renumbered as rule 1.421), "[e]very defense to a claim for relief in any pleading must be asserted in the pleading responsive thereto, or in an amendment to the answer within 20 days after service of the answer...." The question here is whether parental immunity is an affirmative defense that must be pled. It appears that it is, and by failing to raise the issue in his answer, the defendant has waived it.
An affirmative defense is "`one resting on facts not necessary to support plaintiff's case.'" Bond v. Cedar Rapids Television Co., 518 N.W.2d 352, 355 (Iowa 1994) (quoting Erickson v. Wright Welding Supply, Inc., 485 N.W.2d 82, 86 (Iowa 1992)). "Thus, any defense which would avoid liability although admitting the allegations of the petition is an affirmative defense." Erickson, 485 N.W.2d at 86. It is clear under this standard that parental immunity, as it is now applied in Iowa after Wagner, is an affirmative defense. A defendant must show the alleged negligent acts involved an exercise of either parental authority over the child or an exercise of parental discretion in providing care. See Wagner, 340 N.W.2d at 256. Furthermore, Raymond admitted his negligence here, further demonstrating his claim of parental immunity must be an affirmative defense.
While it does not appear this court has directly held parental immunity is an affirmative defense, it has held qualified immunity is. See Dickerson v. Mertz, 547 N.W.2d 208, 214-15 (Iowa 1996) (holding qualified immunity, applicable to acts of executive branch officials carried out in furtherance of their official duties, is an affirmative defense that must be pled). This court has also noted instances in which immunity has been pled as an affirmative defense. See Jain v. State, 617 N.W.2d 293, 296 (Iowa 2000) (noting State pled, as an affirmative defense, the discretionary function exemption to the State's waiver of sovereign immunity); Kulish v. Ellsworth, 566 N.W.2d 885, 888 (Iowa 1997) (defendants amended their answer to assert the affirmative defense of governmental immunity for acts or omissions related to an emergency response under Iowa Code section 670.4(11)); Turner, 304 N.W.2d at 786 ("[D]efendant asserted the doctrine of parental immunity as an affirmative defense."). Other states have specifically held that a claim of parental immunity is an affirmative defense. The Ohio Supreme Court has held immunity is generally an affirmative defense and cited the following, among others, as examples of affirmative defenses: sovereign immunity, official immunity, parental immunity, policeman/fireman immunity, charitable immunity, and judicial immunity. BCL Enters., Inc. v. Ohio Dep't of Liquor Control, 77 Ohio St.3d 467, 675 N.E.2d 1, 4 (Ohio 1997); see also McGee v. McGee, 936 S.W.2d 360, 369 (Tex.App.1996) ("Parental immunity is an affirmative defense that ordinarily must be pled to avoid waiver."); Elkington v. Foust, 618 P.2d 37, 40 (Utah 1980) (parental immunity is an affirmative defense that must be pleaded). But see Faul v. Dennis, 118 N.J.Super. 338, 287 *416 A.2d 470, 472 (N.J.Super.Ct.Law Div.1972) (Parental immunity is not an affirmative defense because "surprise is fundamental to the requirement to plead certain defenses affirmatively and it is difficult to imagine a situation where a party could claim surprise to the defense of parental immunity.").

IV. Conclusion.

We conclude the court erred in sustaining the motion to dismiss on parental-immunity grounds because the defendant, having failed to plead it, has waived this affirmative defense. This case has languished in the court system for too long, and the plaintiff's complaint that the parties deserve more considerate treatment by the court system is well-justified. We reverse and remand for further proceedings before another judge.

REVERSED AND REMANDED.
All justices concur except CADY and TERNUS, JJ., who dissent.
CADY, Justice (dissenting).
I respectfully dissent.
The majority failed to reach the dispositive issue in this case by misapplying the waiver doctrine and by failing to recognize the discretion of the trial court.
Even if parental immunity is an affirmative defense that must be pled, the failure of the defendant in this case to raise it until the eve of trial does not constitute a waiver of the defense. Certainly, we recognize a defendant generally waives an affirmative defense if it is not raised in a pleading. Dutcher v. Randall Foods, 546 N.W.2d 889, 893 (Iowa 1996). Yet, the rationale for this waiver rule is founded on the reason certain defenses are required to be raised as affirmative defenses, and others are not. An affirmative defense is one that rests on facts not necessary to support the plaintiff's case. Bond v. Cedar Rapids Television Co., 518 N.W.2d 352, 355 (Iowa 1994). Thus, a fair trial requires a defendant to give notice to a plaintiff of a defense to a claim not associated with proof of the claim so that the plaintiff will be able to present evidence at trial to overcome the defense. Therefore, the pleading requirement provides the essential notice and opportunity to the plaintiff to fully address the defense at trial.
Yet, the waiver requirement comes from the delay in asserting the affirmative defense until the plaintiff has tried the case, not from the procedural requirement of raising it in a pleading. This explains why the waiver rule does not apply when the underlying issue is tried by consent of the parties. Dutcher, 546 N.W.2d at 893. It is also consistent with our liberal approach to allowing amendments to pleadings, even during trial. See Rife v. D.T. Corner, Inc., 641 N.W.2d 761, 767 (Iowa 2002). The idea is that if a defendant holds back on an affirmative defense until it is too late for the plaintiff to address the defense, the defense is waived. In this case, the majority failed to apply the waiver doctrine consistent with its rationale.
In truth, the procedural background of this case is not about waiver, but the discretion of a trial court to permit a defendant to raise a dispositive issue on the eve of trial. Clearly, the trial court has broad discretion in this area, and we are not justified to interfere with such discretion absent a clear abuse of authority. See id. at 766.
In this case, although the immunity issue was presented on the eve of trial, the plaintiff did not suffer the type of prejudice that would support a finding of an abuse of discretion. The issue was solely one of law, and the plaintiff's facts were considered without dispute and in a light most favorable to the plaintiff.
*417 The holding in this case has stripped trial courts of their discretion to consider untimely issues, and expanded the waiver doctrine far beyond its intended parameters. Clearly, the defendant in this case should have raised the untimely defense early in the proceedings. Furthermore, the plaintiff was understandably justified in feeling ambushed at trial and frustrated by the pretrial procedure employed by the defendant. Yet, as repugnant as the procedure may have been, it caused no real prejudice under the circumstances. We should address the dispositive issue raised in this appeal.
TERNUS, J., joins this dissent.
