Fixed error when closing

try catch for logic errors