here if try fails it is not throwing the error Exception. I tried by commenting the daemonize() call. Then they throw the error if try fails.
I could not understand why the daemonize() process does not allow the exceptions to throw.
I could not able to get clue, how to throw error without distrubing the daemonize();.
please help.
You can't use fclose on stdin, stdout, or stderr. And there's no point in closing them when you're duplicating over them anyway, so just remove those altogether.
This likely isn't related to the error, but open() does not return 0 on error, it returns -1. Check if fd<0.
You should also close the original fd of anything you're duplicating once you're done copying it.