Return Statements for Functions

From UVOO Tech Wiki
Jump to navigation Jump to search

There are a lot of ways to return code numbers or exit codes in functions. Always best to just use exceptions and maybe a true or false if it is a test of somesort.

try:

   myfunc()

except MyException:

   ...

else:

   ...

No need to analyze the return value.

Don't bother returning anything, unless you explicitly specify that the function intends to return something useful.

This way you can assume that everything has succeeded if no exception was thrown,

If a function succeeds or fails return a boolean True or False.

If it causes an error, throw an exception.

If it mutates something don't put a return.

shareimprove this answer