Optimistic vs pessimistic code |
I use exceptions. So my code looks like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
try {
doSomething();
doSomethingElse();
finishingTouches();
//...
//...
} catch(io_exception& e) {
//Show messagebox to user and abort transaction
} catch(logic_erroe& e) {
//Try to make sense of error and handle it
//(usually by showing messagebox and aborting transaction.)
}
|
LB wrote: |
---|
I don't write or use code that can fail in an undesirable way |
That is hard to do if you take into account
morons user abilities:
Problem 0: User decided it is a good idea to make whole MyDocuments folder read only.
Ok, my bad, should have used %Appdata% from the beginning.
Problem 1: User thought that file
database in program folder is suspicious and decided to delete it.
Apparently he had some sort of messagebox blindness, so it took 15 minutes to make him confess that there
was messagebox telling why program isn't runnng.
Problem 2: User launches program and then removes
database file because he still doesn't like it.
Sadly he is technically my superior, so I cannot say ewerything I want to him.
Problem 3: Another user launches program from flash drive and plug it off immideatly after.
FINE. Solving this and previous problems by loading everything that might be needed in memory on program startup. I hope you like 2500% memory usage increase.