Question is - where and how to use try/except and if/else operators?
For example - I have function:
# copy php.cgi script
def cpcgi(src, dst):
try:
shutil.copy(src, dst)
if os.path.isfile(dst + '/php.cgi'):
return True
except:
print 'Something going wrong!'
Function stored in separate file. Next, from script it calls like:
import createvhostFuncts as fun
print 'Copying php.cgi file...'
if fun.cpcgi(vdir + 'php-cgi/php.cgi', (vdir + 'php-cgi/' + username + '/' + domain)):
print 'Done.\n'
else:
exit('Error! Exit now.\n')
But - there is lot of functions in createvhostFuncts.py. Thus, I have big list of if/else calls in script and it's looks very... Odd? Useless?
So - what correct way to call functions and where better use try/except - inside function, or in script?
UPD:
For example - in BASH I can use somethig like next:
#!/usr/bin/env bash
func(){
echo "Ya!"
}
if func; then
echo $?
echo "Printed"
else
echo $?
echo "Can't echo!"
fi
And run it with next result:
$ ./m
Ya!
0
Printed
Or with error:
#!/usr/bin/env bash
func(){
eCCCcho "Ya!"
}
if func; then
echo $?
echo "Printed"
else
echo $?
echo "Can't echo!"
fi
$ ./m
./m: line 4: eCCCcho: command not found
127
Can't echo!