Hi Danesh,

In integration tests we used to log the exception and throw it. The reason
is the result will be included in the testng reports.

Thanks

On Wed, Oct 8, 2014 at 9:24 AM, Danesh Kuruppu <[email protected]> wrote:

> One more question, why we do both log exception and throw it inside
> handleException?. It will result in multiple log messages in log file, for
> a single problem in the code.
>
> On Thu, Oct 2, 2014 at 9:32 AM, Dinesh J Weerakkody <[email protected]>
> wrote:
>
>> Hi,
>>
>> I'm just curious about the stranded way of handling exceptions in WSO2
>> products. When I go through source code, I found that we use
>> handleException method in some places (in some places use deferent method
>> such as create new exceptions, catch, log and ignore, etc.) Can someone
>> explain the standard exception handling mechanism in WSO2 products and it
>> will be very helpful for newcomers also. (use cases for each case like when
>> to use what method).
>>
>>
>> When it comes to handleException method, I have another question.
>>
>>
>> *Current handle exception method*
>> public void handleException(String msg, Exception e) throws
>> ProductException{
>>         log.error(msg, e);
>>         throw new ProductException(msg, e);
>> }
>>
>> *Problem*
>> class One{
>>     public void methodOne() {
>>         try {
>>             Two two = new Two();
>>             two.methodTwo();
>>         } catch (WhateverException e) {
>>             handleException("Whatever exception message", e);
>>         }
>>     }
>> }
>>
>> class Two{
>>     public void methodTwo() {
>>         try {
>>             // Database manipulation code goes here
>>         } catch (SQLException e) {
>>             handleException("Cannot complete the transaction", e);
>>         }
>>     }
>> }
>>
>> In handleException method we always create a new Exception. When we have
>> multiple method calls, there will be duplicate stacktraces and the actual
>> exception is printed in very latter part of the stack trace. Sometimes it
>> is bit difficult to trace an error. Is there any specific reason to create
>> new exceptions inside handleException method, instead of throwing same
>> exception object if the exceptions is an instance of ProductException like
>> below sample.
>>
>> public void handleException(String msg, Exception e) throws
>> ProductException{
>>         log.error(msg, e);
>>         if(e instanceof ProductException)
>>                throw e;
>>         throw new ProductException(msg, e);
>> }
>>
>> Thank you.
>>
>>
>> --
>>
>> *Dinesh J. Weerakkody*
>> Software Engineer
>> WSO2 Inc.
>> lean | enterprise | middleware
>> M : +94 727 361788 | E : [email protected] | W : www.wso2.com
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
>
> Danesh Kuruppu
> Software Engineer
> WSO2 Inc,
> Mobile: +94 (77) 1690552
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Waruna Perera
Senior Software Engineer - Test Automation
Mobile: +94 77 3867037
WSO2, Inc.; http://wso2.com/
lean . enterprise . middlewear.
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to