Is this a good practice?

Hi,

I just need to make sure that I am following a good practice by handling errors on the server side:

String sError=null;

try{


//bogus code

}
catch(Exception e)
{
	sError=e.getMessage();
}

    RPCRequest dsRequest = (RPCRequest)req;

    RPCResponse dsResponse = new RPCResponse ("some data");


if(sError!=null)
{
	dsResponse.setStatus(RPCResponse.STATUS_FAILURE);
	dsResponse.setData("Error Occured:"+sError);
}

    rpc.send(dsRequest, dsResponse);

}

Thanks!

and what is the difference with sendFailure? What would appear on the client side in case of a sendFailure is executed and a throwable is passed?

That’s fine, except note you should use the DSResponse class if it’s a DSRequest you’re handling (your code doesn’t check).

sendFailure() is just a shortcut that does substantially the same thing your code is doing.