Throw error if it occurs.
Result can be printed as json or as string.