(a) Except as otherwise provided in subsection (b), if a particular charitable purpose becomes impossible, impracticable, illegal, obsolete, ineffective or prejudicial to the public interest to achieve:
         (1) the trust does not fail, in whole or in part;
         (2) the trust property does not revert to the settlor or the settlor's successors in interest; and
         (3) upon petition by the trustee or trustees, the director of charitable trusts or an interested party other than the settlor, the court may apply cy pres to modify or terminate the trust by directing that the trust property be applied or distributed, in whole or in part, to a charitable purpose which is useful to the community and which fulfills as nearly as possible the general charitable intent of the settlor.
      (b) A provision in the terms of a charitable trust that would result in distribution of the trust property to a noncharitable beneficiary prevails over the power of the court under subsection (a) to apply cy pres to modify or terminate the trust only if, when the provision takes effect:
         (1) the trust property is to revert to the settlor and the settlor is still living; or
         (2) fewer than 21 years have elapsed since the date of the trust's creation.
Source. 2004, 130:1, eff. Oct. 1, 2004.