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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:19:03+00:00 2026-06-07T12:19:03+00:00

I have been playing around with using error handling. In particular with user defined

  • 0

I have been playing around with using error handling. In particular with user defined errors.

However I am not sure if the following approach a bad idea / recommended / plain weird?

import operator
from functools import partial


class GenericError(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)


def errorhandle(error, func):
    print(func.__name__, "says: ", error)
# or perhaps error_dictionary[error]


def f_test_bool(x, bo, y, et, m, ef):
    """ generic boolean test. If boolean_operator(x,y) == True -->  raise passed in Error """
    try: 
        if bo(x,y):
            raise et(m)
        else:
            return x
    except et as err:
        ef(err, f_test_bool)



partial_ne = partial(f_test_bool, 
                     bo=operator.__ne__, 
                     et=GenericError, 
                     ef=errorhandle)

partial_ne( x = 5, 
            y = 6, 
            m = "oops, 5 is not equal to 6" )




>>> imp.reload(errorhandling)
f_test_bool says:  'oops, 5 is not eqal to 6'

my thought was that this way, I could have a simple module that I can re-use, and pipe values through without having to add user-defined errors to any new functions that I write. I thought this would keep things cleaner.

  • 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-06-07T12:19:05+00:00Added an answer on June 7, 2026 at 12:19 pm

    You’re adding a lot of overhead for something that should be simple and obvious. Don’t forget the zen:

    Simple is better than complex.

    Why not simply:

    if 5 != 6:
       raise ValueError('oops, 5 is not equal to 6')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing around with using graphs to analyze big data. Its been
I have been playing around with the MVP pattern using winforms for the last
I am using Sparrow framework. I have been playing with moving sprites around using
I have been playing around with jqgrid, and have the following question. To get
I have been playing around with a simple application for Windows Phone 7 using
I have been playing around with my phonegap app in eclipse using android sdk
I have been playing around with C++11 lately, and came up with the following
I have been playing around with Google Apps Script today and I am trying
I have been playing around a bit with a fairly simple, home-made search engine,
I have been playing around with the Rhino ETL library and really like the

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.