×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    Sydney, Australia
    Posts
    8

    another noob question :)

    How do I log exceptions that happen in my app? I need to have a log file...

    Cheers,
    Ali Shafai

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: another noob question :)

    Quote Originally Posted by AliShafa View Post
    How do I log exceptions that happen in my app? I need to have a log file...

    Cheers,
    Ali Shafai
    hi alishafa
    have look at the wiki recently there are lot of articles on this.
    hope this helps give a feedback.

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: another noob question :)

    Quote Originally Posted by AliShafa View Post
    How do I log exceptions that happen in my app? I need to have a log file...

    Cheers,
    Ali Shafai
    Code:
    import sys, traceback, codecs
    
    #Open the log file
    f=codecs.open("C:\\Python\\exceptionlog.txt", "w", "utf_8")
    
    #When an exception occurs, print it in the file
    #For example:
    try:print 3/0
    except:f.write(unicode(traceback.format_exception(*sys.exc_info())))
    
    #After you are done with the file, close it
    f.close()
    Last edited by bogdan.galiceanu; 2008-04-17 at 12:45.

  4. #4
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: another noob question :)

    Quote Originally Posted by bogdan.galiceanu View Post
    Code:
    import sys, traceback, codecs
    
    #Open the log file
    f=codecs.open("C:\\Python\\exceptionlog.txt", "w", "utf_8")
    
    #When an exception occurs, print it in the file
    #For example:
    try:print 3/0
    except:f.write(unicode(traceback.format_exception(*sys.exc_info())))
    
    #After you are done with the file, close it
    f.close()
    Some notes:

    Opened files cannot be openend in another application in Symbian (i.e. you cannot read file until you close it.)

    Files are per-thread and can be written only in threads which opened them.
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

  5. #5
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: another noob question :)

    Quote Originally Posted by miohtama View Post
    Opened files cannot be openend in another application in Symbian (i.e. you cannot read file until you close it.)
    Well, I do it all the time (using Windows Vista and ConText text editor).

    File does not contain all info due internal buffering, that's true, but situation can be improved by using "f.flush()". Either imemdiately after each "print/write" or only in some places, for example when you know that app will pause to wait user input.

    Closing the file will flush the internal output buffer completely and you get the rest of file content, too.

    Cheers,

    --jouni

  6. #6
    Registered User
    Join Date
    Mar 2008
    Location
    Sydney, Australia
    Posts
    8

    Re: another noob question :)

    Thanks, it works! but not exactly the way I wanted. I was looking for a central place to catch exceptions:

    Class MyApplication:
    def run(self):
    do something that can throw an exception
    .
    .
    .

    try:
    myApplication = MyApplication()
    myApplication.run()
    except:
    LogTheException()


    but, what happens is I have to put the try/catch in my run method or it will not catch the exception.

    any help appreciated.

    Cheers,
    Ali

Similar Threads

  1. Just a noob question
    By daviddu54 in forum Mobile Java General
    Replies: 3
    Last Post: 2007-11-19, 09:40
  2. TKeyCode - noob question
    By passaree in forum Symbian
    Replies: 1
    Last Post: 2007-07-30, 04:45
  3. 6101 Midi noob question...
    By furiousangle in forum General Development Questions
    Replies: 2
    Last Post: 2006-04-29, 15:01
  4. Noob question re: streaming/networking
    By SM2005 in forum Streaming and Video
    Replies: 6
    Last Post: 2005-12-09, 15:20
  5. noob question
    By ppe_manager in forum Mobile Java General
    Replies: 1
    Last Post: 2003-10-19, 09:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×