Unable to supress exception in custom service

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
}

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