Fixing possible segfaults in try/catch blocks