fixed program not closing when exception occur

Signed-off-by: Nicholas Lum <nicholaslum444@hotmail.com>