Detect infinite loop and raise exception

Proof of concept: to see how easy it might be to detect common infinite
loops