vb errors from Python COM object now include the traceback lines

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

vb errors from Python COM object now include the traceback lines

Lloyd Kvam-2
I am upgrading an old windows application from Python 2.4 to Python 2.6.
The application is written in portable Python.  A GUI interface was
created by using Visual Basic (VB 6) and a Python module that wraps the
application as a COM object.

With python 2.4 (and pywin32-210) exceptions resulted in a VB ERR object
where the description was the text from the Python exception.

With python 2.6 (and pywin-217) the description includes the traceback
making the error messages hopelessly confusing to the user.

I could not find any documentation describing the change or offering any
configuration clues.  Comparing the win32com source trees has not
helped.  I could not find a change in the Python code relating to the
traceback appearing in the descriptions.

I am hoping one of you can point me in the right direction.  My
alternative appears to be (painfully) writing some VB code to discard
the traceback lines from  Err.Description.

--
Lloyd Kvam
Venix Corp
DLSLUG/GNHLUG library
http://dlslug.org/library.html
http://www.librarything.com/catalog/dlslug
http://www.librarything.com/catalog/dlslug&sort=stamp
http://www.librarything.com/rss/recent/dlslug

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: vb errors from Python COM object now include the traceback lines

Lloyd Kvam-2
On Thu, 2012-04-19 at 16:32 -0400, Lloyd Kvam wrote:
> I am hoping one of you can point me in the right direction.  My
> alternative appears to be (painfully) writing some VB code to discard
> the traceback lines from  Err.Description.

I read more carefully through Python Programming on Win32 and came up
with this code:

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
class DefaultDebugDispatcher(
        win32com.server.dispatcher.DefaultDebugDispatcher):
    def _HandleException_(self):
        excls,exself = sys.exc_info()[:2]
        if not IsCOMServerException(excls):
            raise COMException(description = str(exself),
                scode = winerror.E_INVALIDARG,
                )
        raise

useDispatcher = DefaultDebugDispatcher
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

I tried several other winerror codes, but they all wiped out my
description.  This seems to work for my purposes.  There is some
additional code that emails traces to me, but I snipped it since it
makes little sense without a lot more context.

Please let me know if I missed a better approach.

Thanks very much for your attention.


--
Lloyd Kvam
Venix Corp
DLSLUG/GNHLUG library
http://dlslug.org/library.html
http://www.librarything.com/catalog/dlslug
http://www.librarything.com/catalog/dlslug&sort=stamp
http://www.librarything.com/rss/recent/dlslug

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: vb errors from Python COM object now include the traceback lines

Mark Hammond-4
On 20/04/2012 8:30 AM, Lloyd Kvam wrote:
> On Thu, 2012-04-19 at 16:32 -0400, Lloyd Kvam wrote:
>> I am hoping one of you can point me in the right direction.  My
>> alternative appears to be (painfully) writing some VB code to discard
>> the traceback lines from  Err.Description.

Hrm - I thought it had always been the case that if you throw an
explicit COMException, then you shouldn't get the traceback - the
traceback only appears for "other" exceptions, which presumably indicate
the exception was unintended.

>
> I read more carefully through Python Programming on Win32 and came up
> with this code:
>
> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""
> class DefaultDebugDispatcher(
> win32com.server.dispatcher.DefaultDebugDispatcher):
>      def _HandleException_(self):
>          excls,exself = sys.exc_info()[:2]
>          if not IsCOMServerException(excls):
>              raise COMException(description = str(exself),
>                  scode = winerror.E_INVALIDARG,
>                  )

Which seems to backup my point - IsCOMServerException() is returning
false, so the exception isn't a COMException, so you turn it into one
and avoid the traceback etc.

Note however that you could just also raise a COMException directly from
the original point - ie, there should be no need to convert to a
COMException if a COMException is thrown in the first place.

How are you throwing the original?  If you thought you were throwing a
COMException then we would want to check you actually are if you still
think so, dig into why IsCOMServerException is failing.

Cheers,

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: vb errors from Python COM object now include the traceback lines

Lloyd Kvam-2
On Fri, 2012-04-20 at 15:52 +1000, Mark Hammond wrote:

> On 20/04/2012 8:30 AM, Lloyd Kvam wrote:
> > On Thu, 2012-04-19 at 16:32 -0400, Lloyd Kvam wrote:
> >> I am hoping one of you can point me in the right direction.  My
> >> alternative appears to be (painfully) writing some VB code to discard
> >> the traceback lines from  Err.Description.
>
> Hrm - I thought it had always been the case that if you throw an
> explicit COMException, then you shouldn't get the traceback - the
> traceback only appears for "other" exceptions, which presumably indicate
> the exception was unintended.
>

The COMException is the code I added.  Up until now I had not translated
the Python exceptions into COMExceptions.  This had worked OK.

> >
> > I read more carefully through Python Programming on Win32 and came up
> > with this code:
> >
> > """"""""""""""""""""""""""""""""""""""""""""""""""""""""""
> > class DefaultDebugDispatcher(
> > win32com.server.dispatcher.DefaultDebugDispatcher):
> >      def _HandleException_(self):
> >          excls,exself = sys.exc_info()[:2]
> >          if not IsCOMServerException(excls):
> >              raise COMException(description = str(exself),
> >                  scode = winerror.E_INVALIDARG,
> >                  )
>
> Which seems to backup my point - IsCOMServerException() is returning
> false, so the exception isn't a COMException, so you turn it into one
> and avoid the traceback etc.
>
> Note however that you could just also raise a COMException directly from
> the original point - ie, there should be no need to convert to a
> COMException if a COMException is thrown in the first place.

The original code is meant to run on any supported OS.  It's just normal
Python.  I do my development work using Linux.  The COM object is
created by simply using a module to wrap the application into a COM
object using the pywin32 services.  Up until now, the Python exceptions
with their error messages simply percolated up to the VB GUI.

> How are you throwing the original?  If you thought you were throwing a
> COMException then we would want to check you actually are if you still
> think so, dig into why IsCOMServerException is failing.
>
> Cheers,
>
> Mark

Thank you very, very much for your efforts integrating Python and
Windows.  The core application is around 14,000 lines of code.  The
wrapper module to turn it into a COM object for deployment in Windows is
just under 600 lines.


--
Lloyd Kvam
Venix Corp
DLSLUG/GNHLUG library
http://dlslug.org/library.html
http://www.librarything.com/catalog/dlslug
http://www.librarything.com/catalog/dlslug&sort=stamp
http://www.librarything.com/rss/recent/dlslug

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32