question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to catch BusinessException in custom built behavior?

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AbdoDabbascommented, Sep 26, 2020

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:

InsertAfter("CommandAcceptor");
InsertAfter("ExceptionRejector");

One of them is not enough, it has to be both.

0reactions
AbdoDabbascommented, Sep 26, 2020

Thanks, @charlessolar for the help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found