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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:19:42+00:00 2026-05-27T03:19:42+00:00

What is the proper exception class to raise when one of my functions detects

  • 0

What is the “proper” exception class to raise when one of my functions detects None passed where an argument value is required? For instance:

 def MyFunction(MyArg1, MyArg2):

     if not MyArg2:
          raise ?Error?

I think I’ve seen TypeError used here (and it’s true that I’m receiving a NoneType where some other type is expected) but that doesn’t strike me as quite right for this situation where I think the Exception could be more explicit.

  • 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-27T03:19:43+00:00Added an answer on May 27, 2026 at 3:19 am

    There is no “invalid argument” or “null pointer” built-in exception in Python. Instead, most functions raise TypeError (invalid type such as NoneType) or ValueError (correct type, but the value is outside of the accepted domain).

    If your function requires an object of a particular class and gets None instead, it should probably raise TypeError as you pointed out. In this case, you should check for None explicitly, though, since an object of correct type may evaluate to boolean False if it implements __nonzero__/__bool__:

    if MyArg2 is None:
        raise TypeError
    

    Python docs:

    • TypeError python2 / python3
    • ValueError python2 / python3
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the proper way to do error-checking in a class? Raising exceptions? Setting
What's the proper way to declare custom exception classes in modern Python? My primary
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
Consider the following code: public class ReadingTest { public void readAndPrint(String usingEncoding) throws Exception
So I have an observer which looks like this: class RecipeObserver < Mongoid::Observer def
What is the proper way to link to functions in a C# DLL from
I'm creating an instance of a class using the TRttiMethod.Invoke function , but when
Using proper MCV with Objective-C can a UIView subclass have @propertys? i.e. in the
EDIT : proper solution: void add(Student s) { if(root == null) root = new
Is there a proper way to use Monotouch.Dialog (iOs) and call a UIViewController when

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.