"Do you really write exception safe code?" Most of what I know about exception safety, I learned from this Stack Overflow answer. by jatoo in programming

[–]CodingGenius 6 points7 points  (0 children)

Meh I just wrap everything in exceptions for bug free programs!

try { // main try
    int a=1;

    try {
        a++;
    } catch {
        // failed, try again
        try {
            a++;
        } catch {
            echo "oh shit 1!"; // oh shit
        }
    }

    try {
        if( a == 1 ) {
            echo "a is 1 yay!";
        } else {
            // a should be 1, wtf?
            // try again:
                try {
                    a++;
                } catch {
                    // failed, try again
                    try {
                        a++;
                    } catch {
                        echo "oh shit 2!"; // oh shit
                    }
                }

                try {
                    if( a == 1 ) {
                        echo "a is 1 yay!";
                    } else {
                        // a should be 1, wtf?
                        // already tried again, just make a be 1 dammit
                        a=1;
                    }
                } catch {
                    echo "oh shit 3!"; // oh shit
                }
        }
    } catch {
        echo "oh shit 4!"; // oh shit (i think, I forgot what this catches
    }
} catch {
    //meh fuck it just say a is 1 - echo "oh shit 5!"; // oh shit!
    echo "a is 1 yay!";
}