I am making a callout to SAP webservice in order to create a customer in SAP. The customer data is nothing but our Account. Now i am getting an exception "IO Exception: Read timed out". i knew that increasing the timeout will solve the issue. But statements inside and after the catch block got executed even after an exception occurred. Is that normal? I need the statements inside the catch block should executed when an exception occurred and the code execution should get stopped. Why this is happening? Is this normal behavior of try catch? Any ideas please...

    public static void CreateCustomer(String accid) {
    //Variable declaration
    CustomerCreateRequestDTO cust = new CustomerCreateRequestDTO();
    sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00 sap1 = new sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00();       
    Map<List<String>,List<List<String>>> mapSAP = new Map<List<String>,List<List<String>>> {};
    List<String> strReqData = new List<String>{};

    sap1.timeout_x = 900;
    sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01 req = new sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01();

    Account acc = [select Account_Group__c, Title__c, First_Name__c, Last_Name__c, House_No__c, Search_Term__c, BillingStreet, BillingCountry, BillingPostalCode, SAP_REGIO__c, BillingCity from Account where Id =: accid];        

    cust.AccountGroup = acc.Account_Group__c;
    cust.Title = acc.Title__c;
    cust.FirstName = acc.First_Name__c;
    cust.LastName = acc.Last_Name__c;
    cust.SearchTerm = acc.Search_Term__c;
    cust.StreetHNo = acc.BillingStreet;
    cust.PostCode = acc.BillingPostalCode;
    cust.Region = acc.SAP_REGIO__c;
    cust.City = acc.BillingCity;
    cust.Country = acc.BillingCountry;


    Account Group   KTOKD
    First Name  NAME1
    Last Name   NAME2
    Title       ANRED   
    Search Term SORTL
    Street/H No.    STRAS

    Postal Code:    PSTLZ
    City:   ORT01
    Region: REGIO
    Country LAND1


    String InputData = 'ZGSEVAST_SDCRTCUST[.]'+cust.Title+'[.]'+cust.Country+'[.]'+cust.FirstName+'[.]'+cust.LastName+'[.]'+cust.City+'[.]'+cust.PostCode+'[.]'+cust.Region+'[.]'+cust.SearchTerm+'[.]'+cust.StreetHNo+'[.]'+cust.AccountGroup;
    req.item = Utility.LoadRequestData(strReqData);
    sapComDocumentSapSoapFunctionsMcS.ZGssmwfmHndlEvntrqst00Response_element ret;
    try {
        ret =  sap1.ZGssmwfmHndlEvntrqst00('',req);
    } catch(Exception ex) {
        ProcessorControl.inFutureContext = true;
        Account ac = [select id, SAP_KUNNR__c from account where id =: AccId];
        ac.SAP_KUNNR__c = 'xxxxxxxxxx';//r.MessageV2;
        update ac;
        sapComDocumentSapSoapFunctionsMcS.Bapiret2 r = ret.DpostMssg.item[0];
    ProcessorControl.inFutureContext = true;
    Account ac = [select id, SAP_KUNNR__c from account where id =: AccId];
    ac.SAP_KUNNR__c = r.MessageV2;
    update ac;


Thanks, Baskaran

  • It would help to put a brief code example illustrating exactly where the code is executing that you are unsure about. It does not even have to be the "real" code, actually, it is better to write up an example that is very brief without extra stuff in it.
    – user6861
    Commented Mar 24, 2014 at 17:03

1 Answer 1


This is indeed normal behaviour.

If you need code execution to stop in the catch block, put a return; statement at the end of that block, or, if that is applicable, don't catch the exception at all.

  • Thanks @guy. but it is a void method. Moreover i need to update a boolean field if the exception occurs. so i wrote little bit of code to perform a DML inside the catch block.
    – Bforce
    Commented Mar 24, 2014 at 16:18
  • That's no problem. You can still return; after doing those actions. They will be executed and after that the method will be stopped (returning nothing, obviously, because it is a void) Commented Mar 24, 2014 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .