Seksjon 3. Kapittel 6
single
Challenge: Build a Robust Data Processing Script
Sveip for å vise menyen
Oppgave
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})".
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 6
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår