Let's say in Apex you have multiple DML calls like update opportunity then you update Account and then you update contact, but it fails on contact so you want to undo the update on Account and opportunity how do you implement that?
Assuming that all 3 of your DML statements are happening in the same transaction, this is what happens by default if you don't catch the DMLException. I.e. There is nothing for you to implement.
When an exception goes unhandled (and thus the entire transaction fails), Salesforce rolls back the changes made as part of that transaction.