Fixed #2212 by adding a flag indicating whether to throw exception