Default behavior for critical errors does not work

We would like to raise critical errors in our service. It is important that we enabled an ‘Outbox’ feature in our service.

So I added such a code inside a message handler:

 // Some logic (e.g store entity to the database)
 if (condition)
 {
       criticalError.Raise("Test critical error", new ArgumentException("Test error"));
 }
 // Send messages through nservicebus to another service

I expected that if my condition is true, then the critical error will occur and the transaction will be rolled back, no messages will be sent to another service.
And according to the documentation the default behavior for critical errors is to log the exception and keep retrying indefinitely: https://docs.particular.net/nservicebus/hosting/critical-errors

However, in my case, the handler was successfully completed: entity stored to the database, message sent to another service.
The only thing that I can see is an error in logs, but no retries happened:

criticalError.Raise isn’t meant to be used within message handlers. It is how we handle problems outside of the message processing pipeline.

Since you are trying to stop processing within your handler, I would suggest just throwing an exception. This will allow the normal message processing recoverability features to kick in.

That will stop message processing, including your handler, which will roll back any transactions (unless you already committed them in your handler), prevent any messages from dispatching (unless you sent using immediate dispatch) and return the message to the queue so it can be retried.