Question: i am raising exception using

```
if UserId == '' and Password == '':
    raise Exception.MyException , "wrong userId or password" 

```

but i want print the error message on same page

```
class MyException(Exception):
    def __init__(self,msg):
        Exception.__init__(self,msg)

```

Answer: 
You are not using the [Users API](http://code.google.com/appengine/docs/python/gettingstarted/usingusers.html)? Assuming you are handling a POST request, how about this:

```
class LoginError(Exception):
    CODES = { 'mismatch': 'Wrong credentials', 'disabled': 'Account disabled' }
    ...

try:
    // your authentication code
    raise LoginError('mismatch')
    ...
    raise LoginError('disabled')
except LoginError as e:
    self.redirect(your_login_url + '?err=' + e)

# In login page you must not print arbitrary GET parameter directly
err_reason = LoginError.CODES[self.request.get('err')]`

```

(Login request should be using POST method because it changes the server's state, and it's good habit to redirect after a POST, thus a redirect.)
Why raising an exception instead of just stop function execution and redirect to new page using return statement