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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:04:13+00:00 2026-06-04T10:04:13+00:00

class ShortInputException(Exception): ”’A user-defined exception class.”’ def __init__(self, length, atleast): Exception.__init__(self) self.length = length

  • 0
class ShortInputException(Exception):
'''A user-defined exception class.'''
          def __init__(self, length, atleast):
                Exception.__init__(self)
                self.length = length
                self.atleast = atleast
try:
          s = raw_input('Enter something --> ')
          if len(s) < 3:
                raise ShortInputException(len(s), 3)


except ShortInputException, x:
           print 'ShortInputException: The input was of length %d, \
           was expecting at least %d' % (x.length, x.atleast)

I dont understand the syntax of this line: except ShortInputException, x:

what is x here for ??
and why is it acting as an object ???

waht does this line do ? : Exception.__init__(self)

Thanks

  • 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-04T10:04:14+00:00Added an answer on June 4, 2026 at 10:04 am
    except ShortInputException, x:
    

    catches an exception of class ShortInputException and binds the instance of the exception object to x.

    The more common syntax for this is

    except ShortInputException as x
    

    which is to be preferred as described in PEP3110. Unless you need to support Python 2.5, you should use the as version.


    Exception.__init__(self)
    

    calls the constructor for the super class, the class that this user defined class derives from.

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

Sidebar

Related Questions

class Anketum < ActiveRecord::Base has_one :user class << self def search(params) self.scope :h, :conditions
class MyClass(object): def __init__(self): self._my_secret_thing = 1 def _i_get(self): return self._my_secret_thing def _i_set(self, value):
class test: def __init__(self, val): self.val = val self.val.lower() Why doesn't lower() operate on
class Package: def __init__(self): self.files = [] # ... def __del__(self): for file in
class ToBeDeleted: def __init__(self, value): self.value = val # Whatever... def __del__(self): print self.value
class Article(models.Model): def user_may_see_full_version(self, user): # do something very sophisticated with the user return
class Tasks(object): def __init__(self, container=None): if container is None: container = [] self.container =
class person(): def __init__(self): self.height = 3.0 self.weight = 240.0 self.temp = 99.23 self.statlist
class ITestType(object): Sample interface type __metaclass__ = ABCMeta @abstractmethod def requiredCall(self): return class TestType1(object):
class CreateMatches < ActiveRecord::Migration def self.up create_table :matches do |t| t.integer :result_home t.integer :result_away

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.