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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:32:14+00:00 2026-05-26T21:32:14+00:00

I want to check for errors in a particular background file, but the standard

  • 0

I want to check for errors in a particular background file, but the standard error stream is being controlled by the program in the foreground and the errors in the file in the question are not being displayed. I can use the logging module and write output to a file, though. I was wondering how I can use this to log all exceptions, errors and their tracebacks.

  • 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-26T21:32:15+00:00Added an answer on May 26, 2026 at 9:32 pm

    It’s probably a bad idea to log any exception thrown within the program, since Python uses exceptions also for normal control flow.

    Therefore you should only log uncaught exceptions. You can easily do this using a logger’s exception() method, once you have an exception object.

    To handle all uncaught exceptions, you can either wrap your script’s entry point in a try...except block, or by installing a custom exception handler by re-assigning sys.excepthook():

    import logging
    import sys
    
    logger = logging.getLogger('mylogger')
    # Configure logger to write to a file...
    
    def my_handler(type, value, tb):
        logger.exception("Uncaught exception: {0}".format(str(value)))
    
    # Install exception handler
    sys.excepthook = my_handler
    
    # Run your main script here:
    if __name__ == '__main__':
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Flexgrid I want to check the background color of the particular cell... Code
I want to check whether a string is a file name (name DOT ext)
I want to check if a particular page gets redirected or not. However, whenever
I want to check a particular website from various locations. For example, I see
I want to check that a file system path is valid and safe to
I want to check a script for syntax errors. In both 2.x and 3.x,
I have some client-side JavaScript code and want to check that file for syntax
I don't want check if an item with a value exists in the arraylist,
I want to check the integrity of a backup of a Ubuntu disk, copied
I want to check to see if an XML document contains a 'person' element

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.