Fog Creek Software
g
Discussion Board




exceptions considered harmful

Hi,
personally I prefer the exception mechanism with
try{}catch(){}finally{} but there are at least
2 other systems as alternativ to status return
and exceptions:

a) check the status in every call
    status = function1(status, ...);
    status = function2(status, ...);
    if (status == STATUS_OK)
    {
        /* report success */
    }
    else
    {
        /* cleanup */
    }

    int function1(int status, ...)
    {
        if (status == STATUS_OK)
        {
            /* ... */
        }
        return status;
    }

b) the OO way
    abc xy;
    xy.function1(...);
    xy.function2(...);
    if (xy.isOK())
    {
        /* report success */
    }
    else
    {
        /* cleanup */
    }

    class abc {
    privat:
        int m_status;
    public:
        abc() { m_status = STATUS_OK };

        int isOk() { return m_status == STATUS_OK; }

        void function1(...)
        {
            if (isOk())
            {
                // ...
            }
        }
    }

greetings from Austria
Leopold Faschalek

Leopold Faschalek
Tuesday, October 21, 2003

*  Recent Topics

*  Fog Creek Home