changed try-catch to do-while