salesforceのtry、cahch、ロールバックの例を共有します。
Savepoint sp = Database.setSavepoint();
try {
Merchandise__c m = new Merchandise__c();
insert m;
} catch(DmlException e) {
System.debug('The following exception has occurred: ' + e.getMessage());
Database.rollback(sp);
}