Fix if-else-throw codes to contract-based