On 02/10/12 09:27, Gustaf Nilsson wrote
> So where would i catch any error that could happen within my app? will
> i have to add my try: to every method of every object??
>
Hi gustaf

I did something similar to this some time ago:
I catch (hopefuly) every pyjamas error and report it to server, with
error message and traceback.
It is not very straightforward, and sometime traceback is wrong or lost,
but sometimes it useful.
And I suspect this is not the 'right' way.
I attached my source. Used like this:
---
    def initPyjsErrors( self ):
        setOnPyjsError(self.onPyjsError)

    def onPyjsError( self, msg, url, linenumber ):
        print 'pyjs error: msg=%r, url=%r, line=%r' % (msg, url, linenumber)
        _, trace = getPyjsError()
        self.handleInternalError(msg, trace)
---
Seva

# global error handler

from pyjamas.Window import setOnError
from __pyjamas__ import JS
import traceback
import sys


def setOnPyjsError( fn ):
    setOnError(fn)

def getPyjsError():
    if hasattr(sys, 'trackstackstr'):
        errClass, error, tb = sys.exc_info()
        if tb:
            trace = sys._get_traceback_list(error, tb)
            if trace:
                trace = ''.join(trace)
            else:
                trace = sys.trackstackstr(JS("$pyjs.trackstack.slice(0,-1)"))
        else:
            trace = ''
        return (error, trace)
    else:
        type, value, tb = sys.exc_info()
        return (unicode(value), ''.join(traceback.format_tb(tb)))

Reply via email to