added some codes for catching runtime error