So apparently, the gradient is still computed, even when the backward function throws the NotImplementedError.
import torch as th
from torch.autograd import Variable

v = Variable(th.randn(10), requires_grad=True)
m = v > 0.5
w = v[m]
try:
    w.mean().backward()
except NotImplementedError:
    # raise
    pass

print(m)
print(v.grad.data)

This prints:
Variable containing:
 1
 0
 0
 1
 0
 0
 0
 0
 0
 0
[torch.ByteTensor of size 10]


 0.5000
 0.0000
 0.0000
 0.5000
 0.0000
 0.0000
 0.0000
 0.0000
 0.0000
 0.0000
[torch.FloatTensor of size 10]

As expected, the script fails when pass is replaced by raise under the try-except clause.