How to catch BusinessException in custom built behavior?
See original GitHub issueHi Charles,
I was trying to build a custom behavior to catch exceptions and publish a notification, and also tried to follow this tutorial about Subscribing to Error notifications from ParticularSoftware site, but I can’t catch any BusinessException
thrown.
In my system I’m not using the Command
method in the class BusExtensions
in Aggregates.NET, I’m using directly the bus.Send
like in the method PassiveCommand
in the pre-mentioned class.
I looked in the source code and figured out the library is handling it in the ExceptionRejector
class, any way to catch the exception? and way to remove this step? because I couldn’t, 3 steps are depending on each other:
- CommandAcceptor
- UnitOfWorkExecution
- ExceptionRejector
I tried this and it’s not working:
endpointConfiguration.Pipeline.Remove("CommandAcceptor");
endpointConfiguration.Pipeline.Remove("UnitOfWorkExecution");
endpointConfiguration.Pipeline.Remove("ExceptionRejector");
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
java - Try/Catch everything and rethrow Business Exceptions
First of all, it's never recommended to have a generic catch block that catches and instance of Throwable or Exception , unless it...
Read more >Catch BusinessRuleException in Try Catch avoiding the ...
Or is there a way to change the behaviour to first check if there is a CATCH block and only pass the exception...
Read more >Clean Code and the Art of Exception Handling
There is nothing wrong with the previous code. But overusing these patterns will cause code smells, and won't necessarily be beneficial. Likewise, misusing...
Read more >5 Reasons Why Business Exceptions Are a Bad Idea
An article discussing some reasons why you shouldn't work with exceptions when validating business rules.
Read more >Handling exception using custom exception
Catch allows you to catch a specific type of exception, such as a DmlException, a QueryException, or a SuperUncoolException.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The steps are as following:
MyFailedMessageNotification
->ExceptionRejector
->MyHandler
->ExceptionRejector
(this one swallows the exception at line 53 and do return instead of throw again) ->MyFailedMessageNotification
There steps between those I didn’t mention, but these are the important ones as I think.
I solved the issue by adding these two lines in the registration of my behavior:
One of them is not enough, it has to be both.
Thanks, @charlessolar for the help.