.Net: Try it ... Catch paranoia - where does it end?

I think I have something like an "OCD programmer." I like my code to be aesthetically pleasing and clean, and I want it to be “perfect” (as with proper and good management of all possible situations). Often I find that I spend a lot of time just going through the same areas again and again to see where I can optimize and where I can cheat.

So, when it comes to trying to ... block blocks, I feel a bit paranoid about what to invest. I mean, where do I draw a line for which the code should satisfy? For example, perform file processing. Should I put, say, every damned file in a try ... catch block, in case something could happen (the file is blocked by someone / something by an external application, disk corruption, etc.)?

Sometimes it burns my brain, feeling that maybe there is something (which I don’t even suspect) that could bring down some piece of code.

Edit:

I'm not talking about how to use try ... catch to cover up shitty programming, I'm talking about when it comes to operations and procedures that would otherwise be implemented properly, but rely on other factors beyond my control - even if they can be obscure (and this is the point) and occur only in extremely "unsuccessful" conditions, which I did not foresee.

File processing is a good example. When I, as a rule, get inconvenience, this is when I wonder what kind of processing goes behind the scenes of the built-in functionality and how it reacts to my code.

Here is an example:

Dim serverUrl as String = My.Settings.ServerUrl

It involves a disk operation (reading from app.config). Should it be enclosed in a try ... catch block? This is what I mean where it ends.

- . , ? , ? ?

:

, , - - .

, ", , X,.NET - , Y Z, ". - . / , ( ).

, - wiki , , ( ..), , ( ), , , , , , , .

, , - , , .

, , Windows. , , , - , . - ( ), ! , ? - , ? ( , ) , ), "bootstrap.log". ( ), EventLog? EventLog , ( , ..). EventLog , " "..? )

? .

+3
1

, , try... catch, - ( -/- , ..)?

, .

,

, , . , , USB, USB-.

, . , .

,, , ​​, -. IO. - , - , , .

?

2003 , , :

:

  • A, a, API ,
  • B, b
  • C, c, .

:

  • ( A B), API API),
  • , - ( B C)
  • , .

API .

: -. , , (, , ).

. (, BackgroundWorker) , .

. , StackOverflowException ( !) OutOfMemoryException ( ).

, - , .

+9

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


All Articles