Hi folks,

I'm in a process of implementing a fix for the CarbonContext.java
<https://github.com/wso2-dev/carbon4-kernel/blob/master/core/org.wso2.carbon.utils/src/main/java/org/wso2/carbon/context/CarbonContext.java>
[1]
and I found several concerns. Observations as follows,

   - Empty Catch blocks

  if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {

                    try {
                        registry =
dataHolder.getRegistryService().getConfigUserRegistry(getUsername(),
tenantId);
                        return registry;
                    } catch (Exception e) {
                        // If we can't obtain an instance of the registry,
we'll simply return null. The
                        // errors that lead to this situation will be
logged by the Registry Kernel.
                    }
                    return null;
        }

   - Ignoring of documenting of potential exceptions thrown by methods

 try {

            return
CarbonContextDataHolder.getDiscoveryServiceProvider().probe(null, scopes,
null,
                    getCarbonContextDataHolder().getTenantId());
        } catch (Exception ignored) {
            // If an exception occurs, simply return no endpoints. The
discovery component will
            // be responsible of reporting any errors.
            return new String[0];
        }

What we normally tend to do is, either log, or throw. Catching the
exception just to log it doesn't make much sense. If we can gather some
additional context, create a new exception with new info and wrap the
cause, and throw it. Also, if we log, and throw, and then the client
catches it, logs, rethrows, and so on,what will happen is we will get the
stack trace with the same exception multiple times.

Please advice as to how I should go about handling this.

Thanks
- Pubudu
​
​[1]
https://github.com/wso2-dev/carbon4-kernel/blob/master/core/org.wso2.carbon.utils/src/main/java/org/wso2/carbon/context/CarbonContext.java​

-- 
*Pubudu Dissanayake*
 Software Engineer

WSO2 Inc.; http://wso2.com
lean.enterprise.middleware
Mob: + 94 775 503 304

Blog: http://geekdetected.wordpress.com/
Linkedin: *http://lk.linkedin.com/in/pubududissanayake*
<http://lk.linkedin.com/in/pubududissanayake>
Flickr : https://www.flickr.com/photos/pubudufx/
Twitter: https://twitter.com/GeekInAction
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to