Cake's error handling and finally block

Cake has error handling techniques that you can use to recover from errors or graciously handle exceptions whenever they occur during the build process. Sometimes build steps call external services or processes; invocation of these external dependencies might cause errors that can cause the overall build to fail. A robust build should handle such exceptions without stopping the entire build process.

The OnError method is a task extension that is used when you need to act on an exception generated in the build. Instead of forcefully terminating the script, you can write code to handle the error in the OnError method:

Task("Task1").Does(() =>{}).OnError(exception =>{    // Code to handle exception.});

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.