I have a small Salesforce app called ISV Cockpit that helps AppExchange partners to get notified about their app's unhandled exceptions within subscriber orgs.
For that, this app leverages Salesforce native error emails. So the app is not sending anything.
I am now considering extending the app's scope by reporting already handled exceptions with the same mechanism. The idea goes like this:
The exception is first handled by the app's code:
try { .... } catch(Exception ex) { handle(ex); silentlyRethrow(ex); }
Then some library code converts the exception into a Platform event and publishes it
private void silentlyRethrow(Exception ex) { Exception__e exceptionEvent = convertToEvent(ex); EventBus.publish(exceptionEvent); }
Finally, a trigger unpacks and throws the exception:
trigger ExceptionEvents on ExceptionEvent__e (after insert) { throw deserialize(Trigger.new); }
Can this work? I am currently struggling with serializing and deserializing exceptions but maybe this already indicates my idea is silly.