2

I have a very simple question on C# and C++: is it a good practice to use return in try block? A long time ago I heard that it can produce some troubles for a compiler. But probably the modern compilers can handle this situation. Sample code:

try
{
   //do something
   return 25;
   //do something else
}
catch (Exception)
{
}
Cyber Progs
  • 3,656
  • 3
  • 30
  • 39
Dmitriano
  • 1,878
  • 13
  • 29
  • C++ and C# are *very* different languages, please don't conflate them. For example, it's not good practice in C# to manage pointers; while it is in C++. – Rob Jul 27 '17 at 00:34

1 Answers1

3

You can return at anytime, it's not bad practice to have a return statement in the try block and even the catch block. Actually, it often improves readability

TEK
  • 125
  • 10