views:

35

answers:

1

I am using another service in a Service Oriented Architecture. My service used the other service to save data into the database. Is is good practice for me to rethrow the exception which i get from save service or should i catch the exception and encapsulate it in my result and then just send the result back.

+1  A: 

I like the idea of Result type used to encapsulate the results of an invocation. I don't know what language or framework you're using, but I use C# generic type Result<T> that represents the outcome of the invocation, which indicates the result status, an optional message, an optional result type (as indicated by T), and an optional Exception instance (so I can emit the original exception if I'm in a development or debugging scenario).

From a security standpoint, it is frowned upon to let your exception details bubble up to the initiating client as you could unintentionally expose sensitive information about the internal operations of your application or one of your dependencies. Plus, it just looks bad and is harder for your consumers to work with. If it is possible that a resource can fail, it's better that you wrap that call in a try/catch and route any exceptions through your exception policy and return a negative Result, rather than just let your client blow up.

HackedByChinese
Thanks man. As for language i am using Java 1.4
pete