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

  • Home
  • SEARCH
  • 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 7181693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:36:40+00:00 2026-05-28T17:36:40+00:00

How do I test my parameter if it will raise an exception without actually

  • 0

How do I test my parameter if it will raise an exception without actually raising it, using try and except?

class MyClass:
    def function(parameter):
        pass

parameter is an ambiguous function that may raise 1 or more of any exception, for example:

parameter = pow("5", 5)

A TypeError is raised as soon as the function is called and before the function can execute its statements.

  • 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-28T17:36:41+00:00Added an answer on May 28, 2026 at 5:36 pm

    In a comment to another answer you said: “parameter is another function; take for example: parameter = pow("5", 5) which raises a TypeError, but it could be any type of function and any type of exception.”

    If you want to catch the exeption inside your function you have to call the paramenter (which I’m assuming is callable) inside that function:

    def function(callable, args=()):
        try:
            callable(*args)
        except:
            print('Ops!')
    

    Example:

    >>> function(pow, args=("5", 5))
    Ops!
    

    This is if you really need to call your “paramenter” inside the function. Otherwise your should manage its behaviour outside, maybe with something like:

    >>> try:
    ...     param = pow('5', 5)
    ... except:
    ...     param = 10
    ... 
    >>> param
    10
    >>> function(param)
    

    In this example, to raise an exception is pow not function, so it’s a good practice to separate the the two different call, and wrap with a try-except statement the code that might fail.

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

Sidebar

Related Questions

Possible Duplicate: 'pass parameter by reference' in Ruby? in this example: def test verb
I'm using django_webtest to test my application. I faced with problem when try to
I have some code in a test using Moq: public class Invoice { ...
In a stored procedure, I am trying to test if a parameter is null
Our test department has a series of web tests created using Visual Studio 2005
I spent some time trying to write a 'helper' macro to test a parameter
I have (after quite a bit of work) a web test that will upload
I'm writing a test for a file parser class. The parse method receives a
Is there a way to have the compile deduce the template parameter automatically? template<class
I have C function that takes string pointer as a parameter. This functions returns

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.