Hi there,
Not too sure what the question is, but this may help you out.
Functions in computer programs can return objects or primitive types. Both of these types have cons and pros. Primitive types are easy to work with and are baked into programming langs. Think of them like super basic elements such as protons or electrons in real life.
They are normally the following:
- integers or int
- single float numbers
- double float numbers for long numbers
- booleans or bool
Depending on the lang, there might be more prim types. But they follow the same principles regardless.
Booleans (bool) are types that hold 1 value, and that value can be either true or false. But nothing else. They are useful for conditions or in cases where you know that only two outcomes are possible. Functions use booleans to indicate success or failure. Or answering yes/no situations. ETC…
To use booleans, you use operators like == or != in statements
For example:
age = 23
if age is greater then 10 do
say "you are older than 10"
else
say "not older then 10"
behind the scenes, this if statement returns a boolean. EASY to read/understand.
Errors are special objects and objects are more complex than the primitive types. I won’t go into details, if you want to know more then you can google it. 
After saying that, if programs use errors to indicate something, there will be more code. Specifically error handling code. You have to throw errors and catch exceptions to make sure your program doesn’t crash in the middle of something important like funding you money.
You will have to write try statements like so:
try this
refund steve
catch (someError)
revert the funds ASAP
With booleans, you just have to check and then the function that returns a boolean can automatically revert what it was doing.
Hope that helps you!