This may be a bit redundant with nvteighen's post but I'll provide a sample. Are you doing/wanting something like this?
Code:
def load_files(path):
exceptions = []
try:
if not path:
raise CustomException1("PATH is empty!")
except CustomException1, inst:
exceptions.append(inst)
try:
if len(path) > 1234:
raise CustomException2("PATH is too long!")
except CustomException2, inst:
exceptions.append(inst)
try:
if not os.path.exists(path):
raise CustomException3("PATH doesn't exist!")
except CustomException3, inst:
exceptions.append(inst)
#... get file_content in here
# could also use the above methodology to generate
# warnings about the file
return file_content, exceptions
If so... I would agree with nvteighen that you aren't using Exceptions in the way that they are intended. Now that isn't always a bad thing to do (thinking outside the box), but it may be clearer to other coders/maintainers/yourself-later if you just append strings to your exceptions list of the 'warnings' that you are creating. Because handling exceptions in this manner is basically that. You are logging warnings, where exceptions are generally meant to stop execution. Catch clauses just anticipate what things could go wrong to continue running smoothly or to die gracefully. IMHO it is best to handle exceptions as they come up one at a time.... did I make any sense?
Anyway, this may not be what you've done
Bookmarks