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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:06:01+00:00 2026-05-27T06:06:01+00:00

I’m having some trouble getting my head around how best to solve this situation

  • 0

I’m having some trouble getting my head around how best to solve this situation (mostly due to lack of experience I think).
I have written a couple of definitions in a single class that are called from a Main to perform certain tasks. It is assumed the Main could be written by anyone for a number of purposes, so killing the code in the class definition is not preferable. One basic rule of these definitions is, if def1 does its tasks successfully, def2 can be called. But if def1 fails, def2 must not be called as it will fail also.

e.g. semi pseudo code, without exceptions:-

# Test.py
if __name__ == '__main__'
    # variables imported from a file
    var1 = a
    var2 = b

    class.def1(var1, var1)
    class.def2(var_from_def1)

Initially I just performed a sys.exit() in the def1 except:, but as mentioned previously, killing the whole program was undesirable and that it would be preferable to let the exception be thrown and let the Main control whether to call def2.

From my understanding of exceptions (as limited as it is) this wouldn’t work as the exception operation needs to have already been defined before it is raised. Unless it can be defined in Main, but I’d rather Main has an option to do that.

A preferred solution would be for the Main to import the variables, pass them to def1, if def1 failed and Main was not set up to catch the exception the following call to def2 would be cleanly stopped (without killing the process or displaying a fail), no idea how to do that, or if the Main was catching exceptions it could stop the call to def2, load in another set of variables and try def1 again.

Here is a conceptual view of the code which may help understand where I’m coming from.

# Test.py
if __name__ == '__main__'
    # variables imported from file
    var1 = a
    var2 = b

    while new variables to pull from file:
         try:
             class.def1(var1, var1)
         except:
             print 'def1 exception thrown'
         else:
             class.def2(var_from _def1)


 # class.py
 class class(object):
     def def1(self, var1, var2):
         try:
             do something potentially flawed
         except:
             # this is where I get stuck, not sure how or if I can pass an exception back to the main to decide what to do
             sys.stdout.write('didn't work')
             return something

Sorry, it does look messy, it’s a combination of a few ideas for solutions I had, which probably shouldn’t be mixed together.

Any suggestions would be great. I have read a few books and forums regarding exceptions but just can’t grasp how to best resolve this scenario.

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-05-27T06:06:01+00:00Added an answer on May 27, 2026 at 6:06 am

    One basic rule of these subclasses is, if subclass1 does its tasks
    successfully, subclass2 can be called. But if subclass1 fails,
    subclass2 must not be called as it will fail also.

    Write a third class, or a module function? Or the two classes shouldn’t have been decomposed as independent if they truly are dependent on one another.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build

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.