Abschnitt 2. Kapitel 6
single
Challenge: Chain Exceptions for Better Debugging
Swipe um das Menü anzuzeigen
Aufgabe
Swipe to start coding
Practice chaining exceptions to preserve error context in a multi-step data processing script. Each step may throw its own custom exception if it fails. You must chain exceptions so that if a later step fails, the original exception(s) are not lost, and the full context is available when catching the error.
- Call
processStepOne,processStepTwo, andprocessStepThreein order, passing the output of one as the input to the next. - If
processStepOnethrows an exception, throw a new genericExceptionwith message "Processing failed at step one" and chain the original exception. - If
processStepTwothrows an exception, throw a new genericExceptionwith message "Processing failed at step two" and chain the original exception. - If
processStepThreethrows an exception, throw a new genericExceptionwith message "Processing failed at step three" and chain the original exception. - If all steps succeed, return the final result.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 6
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen