Handle error using custom exception and use each