Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3949558
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:30:28+00:00 2026-05-20T01:30:28+00:00

In my Pylons application I’d like to be able to throw exceptions anywhere in

  • 0

In my Pylons application I’d like to be able to throw exceptions anywhere in the code and have the non-fatal ones intercepted in a central point, so that I could return a “friendly” error page such as “Sorry, I can’t do that”.
Fatal exceptions instead should go to the default error handler, that sends me an error report by email and returns to the user the standard “internal server error”.
Right now I’m using something like this in BaseController.__call__:

try:
    return WSGIController.__call__(self, environ, start_response)
except Exception, exc:
    if self.is_nonfatal_exception(exc):
        start_response("200 OK", [("Content-type", "text/plain")])
        return ["Sorry!"]
    raise

but is this the recommended way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:30:28+00:00Added an answer on May 20, 2026 at 1:30 am

    Yes, this looks fine.

    Also take a look at pylons.controllers.utils.abort(). Anywhere in your controller code you can do abort(some_http_code[, message]). Typical HTTP codes to be used with this would be 404 (“Page not found”, client is looking for something that’s not there), 403 (“Forbidden”, user is not allowed to access that page/resource), 400 (“Bad request”, request parameter validation failed) and others. This function also works by throwing special exceptions, then catching them and returning standard error pages somewhere from middleware stack.
    Of course, you can also call abort() from models and other places, not just controllers. But this would be bad style, mixing controller logic with model logic, jumping levels of abstractions.

    Finally, for error conditions that you expect to be common, consider not using exceptions, but using return codes of functions instead. Exceptions that bubble up long way may break encapsulation (distant components need to know about each other’s exceptions, and how these should be handled) .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code as a middleware in an pylons application: import testing.model
I have a Pylons application using SQLAlchemy with SQLite as backend. I would like
I have installed pylons based application from egg, so it sits somewhere under /usr/lib/python2.5/site-packages.
I have a Pylons web application served by Apache (mod_wsgi, prefork). Because of Apache,
Have you tried Psyco in a wsgi application (custom, Pylons, Django...)? What does your
I have a Pylons app where I would like to move some of the
I currently have a Pylons application running with a basic user system set-up. I
We're building a blog-like Pylons web application that uses CKeditor and allows to upload
I've created a new Pylons application and added a controller (main.py) with a template
I am developing a Web application in Pylons on the Mac. My development server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.