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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:36:38+00:00 2026-06-05T21:36:38+00:00

In my application, I’m loading some data from a file. This can fail and

  • 0

In my application, I’m loading some data from a file. This can fail and raise an exception. As a consequence, I want to log a WARNING and continue to load next data.

I’m doing it like that :

try:
    data_A = getDefaultConf(param_1,param_2)
except Exception as e:
    log(WARNING, "Failed to get default parametres: "+str(e))
try:
    data_B = getDefaultConf(param_1,param_3)
except Exception as e:
    log(WARNING, "Failed to get default parametres: "+str(e))
try:
    data_C = getDefaultConf(param_4,param_5)
except Exception as e:
    log(WARNING, "Failed to get default parametres: "+str(e))
try:
    data_D = getDefaultConf(param_4,param_6)
except Exception as e:
    log(WARNING, "Failed to get default parametres: "+str(e))
try:
    data_E = getDefaultConf(param_4,param_7)
except Exception as e:
    log(WARNING, "Failed to get default parametres: "+str(e))

It works but looks heavy. So, my question is: does it exist a way to do it lighter?
It could be something working like that:

try:
    data_A = getDefaultConf(param_1,param_2)
    data_B = getDefaultConf(param_1,param_3)
    data_C = getDefaultConf(param_4,param_5)
    data_D = getDefaultConf(param_4,param_6)
    data_E = getDefaultConf(param_4,param_7)
except Exception as e:
    log(WARNING, "Failed to get default parametres: "+str(e))
    # Here something that could work like a "continue" statement so that if loading of
    #  data_2 fails it will store the log and continue by trying to load data_3, etc.

I ever saw some answers in other posts suggesting to put it in the loop but, would not it be heavier to manage my parametres?

I’m waiting for any suggestion in this way. Whatever the case my code is working. So, it’s just a question of curiosity on a problem that could also help other programmers…

  • 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-05T21:36:41+00:00Added an answer on June 5, 2026 at 9:36 pm

    In this case I might introduce a new function (assuming you can’t or don’t want to change the existing getDefaultConf):

    def getDefault(x, y):
        try:
            return getDefaultConf(x,y)
        except Exception as e:
            log(WARNING, "Failed to get default parametres: "+str(e))
        return None
    
    data_A = getDefault(param_1,param_2)
    data_B = getDefault(param_1,param_3)
    data_C = getDefault(param_4,param_5)
    data_D = getDefault(param_4,param_6)
    data_E = getDefault(param_4,param_7)
    

    The only difference here is that you’ll get None back for calls that result in an exception. This may or may not be acceptable for your application.

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

Sidebar

Related Questions

Application stores configuration data in custom section of configuration file. This information is used
Application.Run(form); Actually I tried to call this from my project. I got this exception.
Application requests KML data through AJAX from server. This data is stored in javascript
Application is running in my local system app.config file <add key=dbconn value=Data Source=(local);database=VTech;User ID=sa;Password=sa;
Application-Stack: Rails3, CanCan, Devise, Shoulda I've got some nested Resources and want to test
Application: This is a workshop proposal system for a conference. A user can create
My application want to upload data to backend. Upload functionality available 2 places. One
Application.Run(new Main()); This line gives TypeInitializationException was unhandled after I switched from 3.5 to
// Application Drupal 7 // Problem Background My website imports product data from a
Application I develop requires several data sources (2 RDBMS and one file storage) to

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.