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 940811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:01:00+00:00 2026-05-15T22:01:00+00:00

I have custom exceptions in my django project that look like this: class CustomFooError(Exception):

  • 0

I have custom exceptions in my django project that look like this:

class CustomFooError(Exception):

    def __init__(self, msg="Something went wrong with Foo."):
        self.msg = msg

    def __str__(self):
        return repr(self.msg) 

At various points in my code I will raise exceptions like this:

raise CustomFooError("Things are going badly")

When Django catches these errors, in debug mode I get django’s standard pretty stack-trace page. But I never see my error messages — “Things are going badly” never shows up in the debug error page.

It seems they should show up as the Exception Value on the error page. I walked back through the django source far enough to find out that this is the value field from sys.exc_info() which is consistently tersely documented as “[the exception’s] associated value or the second argument to raise, which is always a class instance if the exception type is a class object.” Unfortunately, I don’t know what to do with this information.

So my question is: How should I be writing and raising my custom exceptions to get more useful data to show up in places like the django error screen?

  • 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-15T22:01:01+00:00Added an answer on May 15, 2026 at 10:01 pm

    I would just use super and let the constructor of Exception handle assigning the msg attribute:

    class CustomFooError(Exception):
    
        def __init__(self, msg=None):
            if msg is None:
                msg = 'Something went wrong with Foo.'
            super(CustomFooError, self).__init__(msg)
    

    I just tested this from within a Django environment and it correctly displayed the message I passed to the exception constructor or the default one if None was passed.

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

Sidebar

Related Questions

I have a custom exception class with a show() method that shows exceptions in
Does it good idea to have custom exception like IllegalArgumentException and throw it in
I have a custom exception class which contains some additional fields. I want these
I am creating some custom exceptions in my application. If I have an exception
I have a requirement to create custom exception for the exceptions generated by my
When I have my custom errors disabled, Elmah is taking all exceptions that occur
I have a custom exception class: public class MyException: Exception { public MyException(MyExceptionEnum myError)
I have created a custom exception however when it is fired, I'm not getting
I have following code using hibernate to throw a custom exception on error and
I have custom UITableViewCell . It contains UITextLabel . When I press this cell

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.