The Chronomancer wizard archetype gains the ability to reclaim ineffective spells using the Rewind feature:
As an immediate action after losing a spell due to a failed concentration check or after casting a spell that had no effect (such as due to successful saving throws, a failed caster level check to overcome spell resistance, or other immunities), the chronomancer can expend a number of points from his temporal pool equal to half the spell’s level (minimum 1) to immediately prepare the spell again, as if it had not been cast. Any material components expended in the original casting remain expended, as are actions used to cast the original spell.
Usually, this is pretty easy to judge... Failed your check vs. SR? Works. Enemy Saved on a negates spell? Works. Hit your ally who it did affect? Doesn't work.
However, is it valid to use this ability if an enemy counterspells your attempted spell?