Use if-else to check data type for insert_data() instead of using try-catch.