0

Can someone please explain to me just exactly this try/catch is doing? It doesn't seem to make any sense to me. Thank you in advance.

    case '\r':
        if (Choice==(CancelIndex+1))return;                
        try{(*Action[Choice-1])();}
        catch(...){}
        system("cls");
        Choice = 1;
        break;

    case char(27):
        if ((CancelIndex+1)==ItemCount)return;
        try{(*Action[ItemCount-1])();}
        catch(...){}
        Choice = 1;
        break;

Edited by Dani: Fixed formatting

2
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by spankyg
0

>Can someone please explain to me just exactly this try/catch is doing?
It's swallowing errors, basically ignoring them.

0

Is there really any reason to have in the code, or is this just a half-hearted attempt at trying to error detection?

0

Well, it has a legitimate purpose. The author probably didn't want exceptions to propagate beyond this scope. Without the catch, the unhandled exception would just go on until it hits the first catch or until it goes all the way out of the call stack, in which case the terminate function is called.

I'm not a fan of swallowing exceptions silently (at the very least it should be logged), but I wouldn't call it half-hearted either.

0

Thank you, that makes a lot of sense. I understand whats try to be acheived by using
this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.