OPINION OF THE COURT
ROBERTS, Justice.In this action, appellee Central Dauphin School District seeks to recover $529,000 from its insurance carrier, Appellant American Casualty Company, the amount the district by decree of court has thus far been required to return to its *256taxpayers against whom the district imposed an unlawful tax.
Under the parties’ insurance policy, effective from February of 1973 to February of 1976, appellant agrees
“[w]ith the School District that if during the policy period any claim or claims are made against it as a result of any Wrongful Act occurring during the policy period, [appellant] will pay on behalf of, in accordance with the terms of this policy, all loss which the School District shall become legally obligated to pay.”
“Loss,” the only term consistently disputed in this proceeding, is defined as follows:
“Loss shall mean any amount which the Assured [(including school board members)] or School District are legally obligated to pay, including, but not limited to, any amounts which the School District may be required or permitted to pay as indemnity to an Assured, for a claim or claims made against an Assured for a Wrongful Act and shall include but not be limited to damages, judgments, settlements and costs, cost of investigation and defense of legal actions (excluding from such costs of investigation and defenses, salaries of officers or employees of the School District or any other governmental body) claims or proceedings and appeals therefrom, costs of attachment or similar bonds, provided always, however, such subject of loss shall not include fines imposed by the law, or matters which shall be deemed uninsurable under the law pursuant to which this policy shall be construed.”
Central Dauphin paid a premium of $3939 for this policy, coverage it now contends includes the present claim of $529,000 and any further sums which it may be required to refund as a result of the unlawful tax collection.
By resolution dated June 19, .1974, Central Dauphin imposed a tax on the value of the occupations “of all persons residing in Central Dauphin School District . . . who are eighteen (18) years of age or older.” See The Local Tax Enabling Act, Act of December 31, 1965, P.L. 1257, § 2, as amended, 53 P.S. § 6902 (1972). After levy and collection, *257certain taxpayers of the district instituted proceedings in the Court of Common Pleas of Dauphin County challenging the validity of the district’s resolution. Nowhere does the record indicate that Central Dauphin gave appellant notice of the proceedings. The court of common pleas struck down the measure insofar as it sought to impose an occupation tax on “retired persons, housewives and others who have not or do not engage in a gainful occupation . . .and directed payment of refunds. Peifer v. Central Dauphin School District, 97 Dauph. 199, 70 D. & C.2d 35 (1975).
Central Dauphin took no appeal and the trial court’s decree became final. Thereafter the district began to return the tax funds unlawfully collected to those taxpayers who made refund claims under the Act of May 21, 1943, P.L. 349, § 1, as amended, 72 P.S. § 5566b (1968).1
Central Dauphin then sought from appellant an amount equal to the tax revenue it had illegally collected and was required by court order to return to its taxpayers. By letter dated May 22, 1975, appellant took the position that no “loss” had occurred within the meaning of the parties’ insurance policy. Appellant advised Central Dauphin that
“it is doubtful if this event can be insured. Our ‘loss’ definition does have language which says that matters which shall be deemed uninsurable under the law pursuant to which the policy shall be construed are not to be considered part of ‘loss.’ ”
*258Upon appellant’s refusal to make payment, Central Dauphin filed the present action seeking the $529,000, the amount of tax refunds so far paid, “together with an additional sum for further refund claims that may be filed with and paid by [Central Dauphin] prior to trial. . . . ” After a nonjury trial, the court of common pleas entered judgment in favor of Central Dauphin. A panel of the Superior Court affirmed, 271 Pa.Super. 218, 412 A.2d 892 (1979), and this Court granted allowance of appeal.
Central Dauphin relies heavily upon the initial portion of the policy’s “loss” clause, which defines a loss as “any amount which the Assured or School District are' legally obligated to pay. . . . ” It is axiomatic, however, that “[t]o determine an agreement, a writing must be interpreted as a whole, giving effect to all its provisions.” Atlantic Richfield Co. v. Razumic, 480 Pa. 366, 372, 390 A.2d 736, 739 (1978). The concluding portion of the “loss” clause specifically excludes from the definition of loss those matters “which shall be deemed uninsurable under the law pursuant to which this policy shall be construed.” Thus the writing makes clear that not every legal obligation is within the scope of the present insurance coverage. Expressly excluded from coverage are those matters “deemed uninsurable.”
“In general, parties may contract as they wish. . . . ” Restatement (Second) of Contracts Ch. 14 (Unenforceability on Grounds of Public Policy) Introductory Note, p. 46 (Tent. Draft No. .12, March 1, 1977). At the same time, however, freedom of contract is not absolute. “A promise or other term of an agreement is unenforceable on grounds of public policy if legislation provides that it is unenforceable or if the interest in its enforcement is clearly outweighed in the circumstances by a public policy against the enforcement of such terms.” Id. at § 320(1) (When a Term is Unenforceable on Grounds of Public Policy). See also id. at § 233 (Construction Favoring the Public) (Tent.Draft No. 5, March 31, 1970).
*259In our judgment, the public policy of this Commonwealth would be offended by permitting a political subdivision to use public funds to purchase “insurance” against court-ordered and statutorily-mandated refunding of taxes collected through an unlawful taxing measure. Were Central Dauphin’s position to prevail, a school district or any other taxing body would have little reason, if any, to enact only lawful taxing measures. A district would be able to subject its citizens to an unlawful tax measure like the one imposed here, and yet in effect retain the proceeds of the unlawful tax simply by recovering on the claimed insurance coverage.
Neither statutory authority nor our case law permits a device by which a school district’s enactment of an unlawful tax provides the district with the same amount of revenue as if the tax were lawful. School districts may obtain revenues only from lawful taxing measures and legislative appropriations, not unlawful taxation and insurance proceeds. Where an unlawful taxing measure is imposed, a district is obliged by court order and statute to return the unlawfully collected funds to taxpayer-claimants. Refunds are to be paid “out of budget appropriations of public funds. . . . ” Act of May 21, 1943, P.L. 349, as amended (supra note 1). So too, under the Public School Code of 1949, Act of March 10, 1949, P.L. 30, § 631(6), as amended, 24 P.S. § 6-631(6)(Supp.l980), a district may create and incur indebtedness “[t]o pay any refund of taxes decreed by an order of court. 2
Central Dauphin argues that, in enacting its unlawful taxing resolution, it acted in good faith and that it was *260guilty only of “negligence” in failing to pass a lawful taxing resolution. This degree of fault, Central Dauphin claims, is within the scope of the policy coverage.
Even if Central Dauphin were only “negligent,” the consequences of the unlawful tax may not be avoided by the assertion of insurance coverage. Such an assertion contravenes constitutional and statutory requirements. The validity of tax measures is not determined by the good or bad faith or negligence or lack of negligence of the governmental unit imposing the tax. Taxation is a governmental function controlled by constitutional provisions and statutory direction. The exercise of this function must strictly comply with constitutional and statutory controls. See Amidon v. Kane, 444 Pa. 38, 41-42, 279 A.2d 53, 55 (1971); Madway v. Board for Assessment and Revision of Taxes, 427 Pa. 138, 146, 233 A.2d 273, 277 (1967). See also 1 Pa.C.S. § 1928(b)(3); McQuillin, 106 Municipal Corporations Ch. 44 (Taxation), §§ 44.13 & 44.16 (3d ed. 1979).
Because this Commonwealth’s public policy does not permit a school district to make unlawful taxation just as revenue-productive as lawful taxation, it must be concluded that a political subdivision’s return of tax monies to its taxpayers collected by an unlawful tax is uninsurable. Hence there has been no “loss” within the meaning of the insurance policy and no claim lies against appellant. Accordingly, the order of the Superior Court must be reversed, and judgment must be entered in favor of appellant.
Order reversed and judgment entered for appellant.
EAGEN, former C. J., did not participate in the decision of this case.
LARSEN, J., joins the Opinion of the Court and files a concurring opinion.
KAUFFMAN, J., files a dissenting opinion.
. The Act of May 21, 1943, as amended, provides:
“Whenever any person or corporation of this Commonwealth has paid or caused to be paid, or hereafter pays or causes to be paid, into the treasury of any political subdivision, directly or indirectly, voluntarily or under protest, any taxes of any sort, license fees, penalties, fines or any other moneys to which the political subdivision is not legally entitled; then, in such cases, the proper authorities of the political subdivision, upon the filing with them of a written and verified claim for the refund of the payment, are hereby directed to make, out of budget appropriations of public funds, refund of such taxes, license fees, penalties, fines or other moneys to which the political subdivision is not legally entitled. Refunds of said moneys shall not be made, unless a written claim therefor is filed, with the political subdivision involved, within two years of payment thereof.”
. Section 631(6) of the Public School Code of 1949, as amended, provides:
“The board of school directors in any school district may, in any year, create and incur an indebtedness against such school district and issue bonds to secure the same, payable as provided by the act of July 12, 1972 (Act No. 185), known as the ‘Local Government Unit Debt Act,’ or any amendment or re-enactment thereof, for any or all of the following purposes:
* * * * * *
(6) To pay any refund of taxes decreed by an order of court....”