# Unable to supress exception in custom service

**URL:** <https://community.criticalmanufacturing.com/t/unable-to-supress-exception-in-custom-service/683>\
**Category:** Extensibility\
**Tags:** v11.3, business-rules\
**Created:** [January 13, 2023, 10:42am UTC](https://community.criticalmanufacturing.com/t/unable-to-supress-exception-in-custom-service/683 "2023-01-13T10:42:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Roque](https://yyz2.discourse-cdn.com/flex050/user_avatar/community.criticalmanufacturing.com/joao_roque/32/24_2.png) [@Joao\_Roque](https://community.criticalmanufacturing.com/u/Joao_Roque)\
**Post date:** [January 13, 2023, 10:42am UTC](https://community.criticalmanufacturing.com/t/unable-to-supress-exception-in-custom-service/683/1 "2023-01-13T10:42:18Z")

</div>

Hi Team,

I am creating a custom service which will send a custom object in case of any exception. So I am trying to supress the error and return a custom object. But I am getting “Invalid number of start methods” exception catch (CmfBaseException cmfBaseExp)  
{  
//supress  
}  
catch (Exception ex2)  
{  
//ex2 = null;  
//supress  
}

---

<div class="post-metadata">

**Author:** ![Joao\_Roque](https://yyz2.discourse-cdn.com/flex050/user_avatar/community.criticalmanufacturing.com/joao_roque/32/24_2.png) [@Joao\_Roque](https://community.criticalmanufacturing.com/u/Joao_Roque)\
**Post date:** [January 17, 2023, 2:59pm UTC](https://community.criticalmanufacturing.com/t/unable-to-supress-exception-in-custom-service/683/2 "2023-01-17T14:59:01Z")

</div>

**Maximilian Jung** wrote:

Hi Simon,

I was facing the same issue a little while ago, and I did implement it the following way:

public static CustomServiceOutput CustomService(CustomServiceInput CustomServiceInput)

{

Utilities.StartMethod(OBJECT\_TYPE\_NAME, “CustomService”, new KeyValuePair\<string, object\>(“CustomServiceInput”, CustomServiceInput));

CustomServiceOutput CustomServiceOutput;

try

{

// Service Implementation was here

CustomServiceOutput = new CustomServiceOutput();

// Service Implementation was here

Utilities.EndMethod(-1, -1,

new KeyValuePair\<string, object\>(“CustomServiceInput”, CustomServiceInput),

new KeyValuePair\<string, object\>(“CustomServiceOutput”, CustomServiceOutput));

return CustomServiceOutput;

}

catch (Exception ex)

{

if(CustomServiceInput.DoThrowException)

{

throw;

}

CustomServiceOutput = new CustomServiceOutput();

Utilities.EndMethod(-1, -1,

new KeyValuePair\<string, object\>(“CustomServiceInput”, CustomServiceInput),

new KeyValuePair\<string, object\>(“CustomServiceOutput”, CustomServiceOutput));

}

finally

{

CustomServiceOutput = new CustomServiceOutput();

Utilities.EndMethod(-1, -1,

new KeyValuePair\<string, object\>(“CustomServiceInput”, CustomServiceInput),

new KeyValuePair\<string, object\>(“CustomServiceOutput”, CustomServiceOutput));

}

return CustomServiceOutput;

}  
Not sure if that is the correct way to this - and therefore, should be used at the users own risk - but it works fine for me this way.

Hope it helps.

Best regards,  
Maximilian
