Is there a Try agreement?

Sometimes I see methods in the .net structure with the prefix "Try", for example. int.TryParse (..).

I assume this means that the method is the same as int.parse, but wrapped in a try catch?

Does this mean that if I write methods that try to catch them (for example, logging, which I never want to raise an exception), they should also have the prefix "try"?

+3
source share
3 answers

Your guess may be correct, but that does not mean type methods Try***.

The promise is that when called, the method will not throw an exception (how this is managed internally does not matter).

, , , Try*** .

TryParse out, .

:

  • , , /, Try***, ,
+7

, (BeginXXX EndXXX), , , , , , .

, , Try, - .NET , .

, bool out.

- , ; , ; , .NET Framework.

0

The int.TryParse method is NOT equivalent to the try / catch wrapper for int.parse in terms of performance. The purpose of int.TryParse is to avoid the causes of performance impact by throwing exceptions, so it makes no sense to implement int.TryParse as int.parse wrapped in try / catch.

0
source

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


All Articles