On 12 July 2012 16:45, Jason Garber <[email protected]> wrote:
> Hello,
>
> I have a very odd situation.
>
> mod_wsgi 3.3 on RHEL 5 x86_64
>
>
> If I raise an exception in an html-generating function, it is caught just
> fine by my WSGI framework with a try/except block.
>
> If I raise the exact same exception within a plain function called from the
> same place, it causes a 500 internal server error:  mod_wsgi (pid=17007):
> Exception occurred processing WSGI script
> '/home/jason/Code/WhiteBoot4/DevLevel.2/TMTManage/WSGI/Dashboard.wsgi'
>
> I can place an explicit try/except around that exact spot, and it is
> completely skipped.  It's really bizarre.  Any ideas?
>
> Here is a simple example.  Note that I have actually reproduced it with this
> level of simplicity.
>
> def FunctionCalledByWSGIFile():
>   try:
>      RenderHTML()
>   except Exception as e:
>      # output error here
>   ...
>
> def RenderHTML():
>    ...
>    # This way works fine
>    raise Exception("foo")
>    ...
>    # This way causes 500 internal server error
>    data = Select()
>
> def Select():
>    raise Exception("foo")

I have no problem with the following constructed based on what you give.

In both cases will print 'EXCEPTION foo' to log file.

There is no 500 error as the exception is not reraised in that example.

Try using a blind 'except' with type and then use:

  except Exception as e:
     print 'EXCEPTION', e

  except:
     import traceback, sys
     traceback.print_exception(*sys.exc_info())

to see what happens.

Original full test script I used is:

def FunctionCalledByWSGIFile():
  try:
     RenderHTML()
  except Exception as e:
     print 'EXCEPTION', e

def RenderHTML():
   # This way works fine
   #raise Exception("foo")

   # This way causes 500 internal server error
   data = Select()

def Select():
   raise Exception("foo")

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    FunctionCalledByWSGIFile()

    return [output]

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to