This may be simple, but I want to implement custom error logging for a batch class, where handled exceptions get written to a logging object in the database.
So I could use the technique in Andrew's answer here: Can I prevent an insert to be rolled back even if my class (later) runs into an exception?
The wrinkle is that if a handled exception occurs and is logged, I'd still like that batch to count as a "Failure" so that when the user monitors the job in Apex Jobs, it'll still show in the failed batches count.
Make sense? I'm handling the exceptions in this case in order to log them, not because I want them hidden from the user.
Is it possible to do this, and still have the log survive? If I use Andrew's technique, and catch the original err, do a rollback, write the logs, and then throw a new exception, it'll roll back the logs, right? And if I don't do the throw, the batch will count as a success, right?