[ros-dev] Error handling

Jakob Eriksson jakov at vmlinux.org
Mon Apr 11 23:38:26 CEST 2005


Casper Hornstrup wrote:

> The control flow isn't obvious since NTCALL hides much of the logic. You
> should rather split the function into smaller functions with sensible
> names. This will, in many cases, reduce the duplicated error handling 
> code.


Indeed. This was my immediate thought too. Maybe something like
this, or maybe not, but you get the idea.


DoNtXXX()
{
    NSTATUS Status;

    Status = NtXXX();

    cleanupXXX();

    return !NT_SUCCESS(Status);
}


DoNtZZZ()
{
    NSTATUS Status;

    Status = NtZZZ();

    cleanupZZZ();

    return !NT_SUCCESS(Status);
}

DoNtYYY()
{
    NSTATUS Status;

    Status = NtYYY();

    cleanupYYY();

    return !NT_SUCCESS(Status);
}


NTSTATUS DoSomething()
{
    return DoNtXXX() || DoNtYYY() || DoNtZZZ();
}





More information about the Ros-dev mailing list