Hi Soumya,
if you want to fetch the errors produced in Pi i recommend you to use the alert monitoring, you can find several step by step documentation in the scn. If PI has an standard way to monitor this cases, why to do an own development?, even the system can send an email with some relevant information
Regards