You can also try to add exception handling to the suspicious code:
Maybe this helps to find the reason.