Monday 27 June 2011

newCSRTransaction - returns null on error ... or does it?

Well, the documentation states that CSMTransaction.newCSRTransaction returns null if the function fails, ie if the transaction sought is invalid. Perhaps this is true in some cases but it certainly isn't true all the time, as we have observed.

Mysteriously our code was failing and a MNoSuchDealException was being thrown. Where was it coming from? Guess what? It came from CSMTransaction.newCSRTransaction! So those null checks we had were pretty useless in this instance, although I suppose they might be necessary, there's no real way of telling until a null is returned (like the docs state should be the case).

Ho hum, so now we have another wrapper:


public static OptionType<CSMTransaction> NewCSRTransaction(int transactionId, short version)
{
try
{
return CSMTransaction.newCSRTransaction(transactionId, version);
}
catch (MNoSuchDealException)
{
return OptionType<CSMTransaction>.Null;
}
}