Refactored methods with incorrect exception handling

fixing JIRA issue https://wso2.org/jira/browse/CARBON-14992