Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Logging and Rethrowing | Advanced Exception Handling
C++ Exception Handling

bookChallenge: Logging and Rethrowing

In many real-world applications, you may need to log information about exceptions before allowing them to propagate further up the call stack. This helps with debugging and monitoring, while still allowing higher-level code to make decisions about how to handle the error. Your challenge is to write a function that catches an exception, logs a specific message, and then rethrows the same exception so that it can be handled elsewhere.

Tarea

Swipe to start coding

Write a function named logAndRethrow that takes a callable object (such as a lambda or function) as its parameter. The function should execute the callable inside a try block. If any exception is thrown, your function should catch it, print the message Exception caught and logged, and then rethrow the same exception. Do not modify or suppress the original exception; ensure it can still be caught by code outside of logAndRethrow.

Solución

solution.cpp

solution.cpp

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 2
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Logging and Rethrowing

Desliza para mostrar el menú

In many real-world applications, you may need to log information about exceptions before allowing them to propagate further up the call stack. This helps with debugging and monitoring, while still allowing higher-level code to make decisions about how to handle the error. Your challenge is to write a function that catches an exception, logs a specific message, and then rethrows the same exception so that it can be handled elsewhere.

Tarea

Swipe to start coding

Write a function named logAndRethrow that takes a callable object (such as a lambda or function) as its parameter. The function should execute the callable inside a try block. If any exception is thrown, your function should catch it, print the message Exception caught and logged, and then rethrow the same exception. Do not modify or suppress the original exception; ensure it can still be caught by code outside of logAndRethrow.

Solución

solution.cpp

solution.cpp

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 2
single

single

some-alt