Exception Handling

I work in a code base (C # 3.5), which is dotted with exception handling blocks that return true / false when internally in a function that returns 'bool'.

catch (Exception ex) { return false; }

This is the wrong practice. I am thinking of registering an exception and having a local variable (for a function) that will be initialized. And this variable will be returned at the end of the function.

What do you think?

+3
source share
7 answers

The usual accepted way to handle exceptions is to handle them only if you can do something with it . Of course, you can handle the general exception only for magazines, but after that you have to re-raise.

. , , , ...

+4

catch , .

, - .

catchall, ( ).

+4

, .

C, true/false . # .

, .

, , , . .

+1

, . , (, ), , . , dbase, .

, . , , try/catch, . AppDomain.UnhandledException, , , . , , . , , , , .

+1

, , , !

0

bool , , .

0

, false - , , , .

, , .

0

Source: https://habr.com/ru/post/1731982/


All Articles