You may be tempted to have your code respond differently depending on the context in which it has been called and read the callstack for that purpose. That’s not a train you want to ride though. I’ve tried, it stops at some pretty weird stations.
After the “What’s New” webcast I’ve done two days ago, I’ve received questions on some new features introduced with Dynamics 365 Business Central 2021 Wave 2 (version 19) that (due to lack of time) I’ve presented quickly.
One of these features was the new way of raising errors that you can use with version 19, alias the Collectible errors.