Python started to don't show errors and don't stop in errors

First example - Ok - In this xample it’s displaying errors - OK:

def test():
print(‘function test - line 1’)
msg=MIMEMultipart(‘alternative’)
print(‘function test - line 3’)
print(‘function test - line 4’)

print(‘main code - hi’)
test()
print(‘main code - yeh’)


In the example above, python correctly throw a error - “NameError: name ‘MIMEMultipart’ is not defined” (because in the example I don’t put the import commands in the code)


BUT I have another python code (a bigger code), in which I have built in the same code above , and Python it’s not giving error message.
Python executes just the following lines / output:
‘main code - hi’
‘function test - line 1’
‘main code - yeh’

Until some days ago I could get all Python errors in the screen, but now I have this problem above.

(evertyhing else it’s working in my bigger code)

I am using Python 3.9.4
I tested in another machine, with Python 3.7.4 - the same problem occurs
And tested in a third machine, with python 3.5.9 - the same problem occurs

Your second Python code will be catching and suppressing exceptions.
This is nearly always a bad idea.

It probably looks something like this:

try:
    code goes here
except:
    pass

Possibly it does this instead:

# could be called *anything*
def hide_exceptions(type, value, traceback):
    # could contain anything
    pass

sys.excepthook = hide_exceptions

You need to search the second code for anything that hides errors. I
suggest you search for:

  • “except:”
  • “except Exception”
  • “sys.excepthook”

(without the quotes obviously) and hope it is easy to find.

Or find the person who wrote this code and ask them to solve the
problem.

1 Like

Steven,

THANK YOU ! VERY MUCH !

Problem Solved !

My code was:

try:
resultmail=myfunctionsendmail(xxxx,xxx,xxx,xxx);
except:
print(’\nERROR IN MAIL SEND’)

What I’ve learned with your post:

1- Never Call a function with several lines inside a Try
2- Must use the try except in the lines of function

THANK YOU AGAIN