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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:23:27+00:00 2026-05-18T01:23:27+00:00

I have some questions about user-defined exceptions in Python and how they should be

  • 0

I have some questions about user-defined exceptions in Python and how they should be organized in a complete project.

I have a fairly complex python project with some sub-packages that has the following structure (__init__.py omitted):

/docs (Documentation)
/apidocs (generated API documentation)
/askindex (my application package)
    /test (Unit tests directory)
        test_utils.py
        ... (more tests)
    /workers (various worker classes)
        communicators.py
        processes.py
        threads.py
        utils.py
    main.py (contains the starting point)
    data_objects.py (various objects used all around the application)
    settings.py (settings of the application)
README.txt

I would like to implement my own Exception to use them in the modules of the ‘workers’ package for specific errors.

Where should I place these exceptions ? I know that I should have my own base exception which subclasses the standard Exception class and subclass it for my other exceptions. Should I create a new ‘exceptions’ module under ‘workers’ ? Put exception classes in the module in which they’re raised ? In this case, where should I put my base class ? Is my application structure appropriated ?

I am new to exceptions in Python, so please excuse me if the answer is obvious…

  • 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-18T01:23:28+00:00Added an answer on May 18, 2026 at 1:23 am

    In general I’ve found with my own work that when I want a custom type of exception, it’s specific to a particular module or package. If it’s relevant to a module, I put it just in that module. I haven’t yet found a case where it would be neater to have a module or package dedicated to exceptions.

    Examples: if I have a jester module, with a class Juggler in it with a method juggle which can raise a DroppedBall (cue throwing rotten tomatoes or similar), the DroppedBall would be in the jester module. Then the crowd.Person instances could try watching the juggler and except jester.DroppedBall.

    If I had a package food, with various modules in it, fruit, vegetable, etc. which all have an eat method (inherited from food.Foodstuff, doubtless), they might be able to raise a RottenException, which would naturally belong in the root of the food package: __init__.py.

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

Sidebar

Related Questions

No related questions found

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.