Please enclose all the execution in a try catch block so in case that there were an exception it can be caught and could avoid a crash.