Empty error message in python

I am trying to debug an error, I got a “no exception exception” when I first ran it and then later inserted a try / except block to print everything that was.

try: #some code except BaseException, e: print str(e) 

This creates an empty output line, any ideas what it could be?

EDIT: Sorry, hoped there was a specific reason why the error message might be empty. There is no stack trace output, which is why I have to force the try / except block in the first place, I am still programming this thing, so I just let the compiler catch the errors for now. The actual code that throws the error is in the Django application, so it will have some functions from Django.

 try: if len(request.POST['dateToRun']) <= 0: dateToRun = Job.objects.filter(id=jobIDs[i]).values()['whenToRun'].split(' ')[0] if len(request.POST['timeToRun']) <= 0: timeToRun = Job.objects.filter(id=jobIDs[i]).values()['whenToRun'].split(' ')[1] except BaseException, e: print str(e) 

This is the code in the view function. Identifiers jobID is an identifier containing key pairs of values ​​in the format ## Selection: ## (i.e. 17Selection: 17). Sorry I forgot to post this initially.

EDIT: repr (e) provided me with TypeError (), which is better than knowing nothing.

+8
python exception
source share
4 answers

This means that the exception has no message attached. Print the type of exception:

 print repr(e) 

You can also print a trace:

 import traceback # ... except BaseException as e: traceback.print_exc() 

You want to avoid catching a BaseException , however this is no better than requesting for an except: blanket. Instead, catch more specific exceptions.

+9
source share

The result is an empty output line:

 try: raise Exception() except BaseException, e: print str(e) 

Use repr(e) to find out that an exception was thrown.

+4
source share

Try using:

 try: #code except BaseExeption as e: print str(e) 

It seems the easiest to understand and emotional.

+4
source share

Place the try / except block around small sections of code until you find the line of violation. For example, if you have:

 try: a = fn(b) c = fn(a) except BaseException, e: print str(e) 

Then change it to:

 a = fn(b) try: c = fn(a) except BaseException, e: print str(e) 
+1
source share

All Articles