Sectionย 3. Chapterย 6
single
Challenge: Build a Robust Data Processing Script
Swipe to show menu
Task
Swipe to start coding
Combine everything you have learned about validation, exceptions, and safe execution to build a robust data processing script. In this challenge, you will process a batch of data rows, validate each entry, and handle any issues gracefully using exceptions and error logging.
- Validate each data row to ensure the
namefield is present and not empty, and that theagefield is an integer between 0 and 120. - If validation fails, throw a
DataValidationExceptionwith a descriptive message. - In the
importDatafunction, catch anyDataValidationExceptionand throw aDataImportExceptionthat includes the original validation error message. - In the main processing loop, catch
DataImportExceptionand log the error message using thelogErrorfunction. - If data passes validation, return a string in the format
"Imported: {name} ({age})".
Solution
Everything was clear?
Thanks for your feedback!
Sectionย 3. Chapterย 6
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat