Developing Windows based ‘C’ application. And following thing which annoys me a lot.
Say I am calling few CreateFile functions in my main function. Every time CreateFile function is invoked, it checks for result. And in each false statement I need to close and exit from application.
e.g.
Code:
HANDLE h1,h2,h3,h4;
h1 = CreateFile(..,..,..);
if ( false )
{
return;
}
h2 = CreateFile(..,..,..);
if (false)
{
CloseHandle(h1);
Exit;
}
h3 = CreateFile(..,..,..);
if (false)
{
CloseHandle(h1);
CloseHandle(h2);
Exit;
}
h4 = CreateFile(..,..,..);
if (false)
{
CloseHandle(h1);
CloseHandle(h2);
CloseHandle(h3);
Exit;
}
Firstly, do not like multiple exits in routine and on top these wrap up things. Can anybody suggest me any better way of doing it?
I can not use C++ at this moment.
Let me know