Try except - bug?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Askari

    Try except - bug?

    Hi,
    I have a problem with try except :
    example
    ============
    try:
    print "bou!"
    raise "ha!"
    except:
    try:
    fileDest.close( )
    except NameError:
    print "error"
    except:
    import traceback
    traceback.print _exc(file=sys.s tdout)
    ============
    If I run this example alone, I have no problem :
    result
    ============
    bou!
    error
    ============

    but I can't understand why doesn't work in my program :

    (too long for a copy and paste)
    (note : it's at line 353)
    (note : the language of this program is in french, sorry)

    when I run my program, I have this error :
    ============
    Traceback (most recent call last):
    File "C:\Documen ts and Settings\Assemb leur_Man\Bureau \Crypte.py",
    line 355, in crypte
    fileDest.close( )
    NameError: global name 'fileDest' is not defined
    ============

    but I know that 'fileDest' is not always defined but I put this line
    in a try-except!? :-( :-S


    Askari
  • Rene Pijlman

    #2
    Re: Try except - bug?

    Askari:[color=blue]
    >but I can't understand why doesn't work in my program :
    > http://www.cvm.qc.ca/9974331/Temp/crypte.py[/color]
    [...][color=blue]
    >when I run my program, I have this error :
    >============
    >Traceback (most recent call last):
    > File "C:\Documen ts and Settings\Assemb leur_Man\Bureau \Crypte.py",
    >line 355, in crypte[/color]
    ^^^[color=blue]
    > fileDest.close( )
    >NameError: global name 'fileDest' is not defined
    >============[/color]

    That's strange, because there is no fileDest.close( ) on line 355. Are you
    sure the message and the code you are showing us correspond?

    --
    René Pijlman

    Comment

    • Askari

      #3
      Re: Try except - bug?

      9974331@cvm.qc. ca (Askari) wrote in
      news:104c369a.0 312300851.4f237 59e@posting.goo gle.com:
      [color=blue]
      > Hi,
      > I have a problem with try except :
      > example
      > ============
      > try:
      > print "bou!"
      > raise "ha!"
      > except:
      > try:
      > fileDest.close( )
      > except NameError:
      > print "error"
      > except:
      > import traceback
      > traceback.print _exc(file=sys.s tdout)
      > ============
      > If I run this example alone, I have no problem :
      > result
      > ============
      > bou!
      > error
      > ============
      >
      > but I can't understand why doesn't work in my program :
      > http://www.cvm.qc.ca/9974331/Temp/crypte.py
      > (too long for a copy and paste)
      > (note : it's at line 353)
      > (note : the language of this program is in french, sorry)
      >
      > when I run my program, I have this error :
      > ============
      > Traceback (most recent call last):
      > File "C:\Documen ts and Settings\Assemb leur_Man\Bureau \Crypte.py",
      > line 355, in crypte
      > fileDest.close( )
      > NameError: global name 'fileDest' is not defined
      > ============
      >
      > but I know that 'fileDest' is not always defined but I put this line
      > in a try-except!? :-( :-S
      >
      >
      > Askari
      >[/color]


      Ops! For test (to do the error), you must click on button "crypter!" with
      blank textField

      Comment

      • Rene Pijlman

        #4
        Re: Try except - bug?

        Askari:[color=blue]
        >Ops! For test (to do the error), you must click on button "crypter!" with
        >blank textField[/color]

        The program runs fine and displays a dialogue with "!ERREUR! :: Vous devez
        avoir un code pour l'encryption.".

        --
        René Pijlman

        Comment

        • Askari

          #5
          Re: Try except - bug?

          Rene Pijlman <reply.in.the.n ewsgroup@my.add ress.is.invalid > wrote in message news:<1ne3vvobh p2u6mqar4khk84h 64hcmu8h1o@4ax. com>...[color=blue]
          > Askari:[color=green]
          > >Ops! For test (to do the error), you must click on button "crypter!" with
          > >blank textField[/color]
          >
          > The program runs fine and displays a dialogue with "!ERREUR! :: Vous devez
          > avoir un code pour l'encryption.".[/color]

          It's at 355 or 363 the error...

          ============
          Traceback (most recent call last):
          File "C:\Documen ts and Settings\Assemb leur_Man\Bureau \test.py", line 363, in c
          rypte
          os.remove(desti nation)
          OSError: [Errno 2] No such file or directory: ''
          ============

          at line 355 you have : "fileDest.close ()"
          and at line 363 you have : "os.remove(dest ination)"

          What is your version of python? (I have 2.3.2)
          Do you have "Traceback" message in console (when you see the dialog)?

          Askari

          Comment

          • Rene Pijlman

            #6
            Re: Try except - bug?

            Askari:[color=blue]
            >OSError: [Errno 2] No such file or directory: ''[/color]

            If I'm not mistaken this is another exception!?
            [color=blue]
            >at line 355 you have : "fileDest.close ()"[/color]

            No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

            #afficher confirmation
            [color=blue]
            >and at line 363 you have : "os.remove(dest ination)"[/color]

            No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

            pass
            [color=blue]
            >What is your version of python? (I have 2.3.2)[/color]

            I use UltraEdit 8.0 on Windows XP to count the line numbers.

            --
            René Pijlman

            Comment

            • Askari

              #7
              Re: Try except - bug?

              Rene Pijlman <reply.in.the.n ewsgroup@my.add ress.is.invalid > wrote in
              news:gg95vvs4ni 6poiht2siml0htc g9qo73j91@4ax.c om:
              [color=blue]
              > Askari:[color=green]
              >>OSError: [Errno 2] No such file or directory: ''[/color]
              >
              > If I'm not mistaken this is another exception!?
              >[color=green]
              >>at line 355 you have : "fileDest.close ()"[/color]
              >
              > No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:
              >
              >
              > #afficher confirmation
              >[color=green]
              >>and at line 363 you have : "os.remove(dest ination)"[/color]
              >
              > No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:
              >
              > pass
              >[color=green]
              >>What is your version of python? (I have 2.3.2)[/color]
              >
              > I use UltraEdit 8.0 on Windows XP to count the line numbers.
              >[/color]

              euh.... I use UltraEdit 10.10 and "#afficher confirmation" is at line 349
              (it's the same numero in IDLE). Are you sure that your UltraEdit is
              correct? Check the line in IDLE, it's the same?

              Comment

              • Askari

                #8
                Re: Try except - bug?

                Rene Pijlman <reply.in.the.n ewsgroup@my.add ress.is.invalid > wrote in
                news:gg95vvs4ni 6poiht2siml0htc g9qo73j91@4ax.c om:
                [color=blue]
                > Askari:[color=green]
                >>OSError: [Errno 2] No such file or directory: ''[/color]
                >
                > If I'm not mistaken this is another exception!?
                >[color=green]
                >>at line 355 you have : "fileDest.close ()"[/color]
                >
                > No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:
                >
                >
                > #afficher confirmation
                >[color=green]
                >>and at line 363 you have : "os.remove(dest ination)"[/color]
                >
                > No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:
                >
                > pass
                >[color=green]
                >>What is your version of python? (I have 2.3.2)[/color]
                >
                > I use UltraEdit 8.0 on Windows XP to count the line numbers.
                >[/color]

                Batheme! I didn't know that the exception rest in memory after a "catch".
                Finaly, it's my mistake with use of "sys.exc_info() " at line 368.

                But for # of line; check your ultraedit. Are you sure that the line 1 is
                "#! d:/python23/python" ?

                Comment

                Working...