1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ON ERRORLEVEL not being trapped

Discussion in 'Support' started by mrrd, Jun 9, 2010.

  1. mrrd

    Joined:
    Jun 8, 2010
    Messages:
    4
    Likes Received:
    0
    Having a problem with ON ERRORLEVEL, I can't get it to work if the errorlevel is set when an external subroutine is called.
    I created 3 files to demonstrate 1) Main.btm 2) GenerateErrorLevel.btm 3) Sub.btm, Running Main.btm shows how the errorlevel is not generated at the sub level and gets generated within the main batch

    TCC 11.00.49 Windows XP [Version 5.1.2600]
    TCC Build 49 Windows XP Build 2600 Service Pack 3


    :********************************
    :Main.btm File Listing
    ON ERRORLEVEL 1 GOTO ErrHandler
    ON ERRORMSG GOTO ErrHandler
    GOSUB "sub.btm" SomeLabel
    echo Passes External GoSub
    GOSUB SomeLabel
    ECHO Normal Termination
    quit
    :SomeLabel
    Call GenerateErrorLevel 1
    return
    :ErrHandler
    Echo Error generated
    CANCEL 1
    :********************************
    :Sub.btm File Listing
    :SomeLabel
    Call GenerateErrorLevel 1
    return

    :********************************
    :GenerateErrorLevel.btm File Listing
    quit %1
    :********************************
    :Main.btm output
    Passes External GoSub
    Error generated
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,731
    Likes Received:
    80
    That's not going to work. For reasons of compatibility, ERRORLEVEL is not
    assigned (or checked) when you return from a CALL (either an explicit one or
    an implicit one as with your external GOSUB). Changing that would result in
    breaking a *lot* of batch files written for CMD.EXE.

    You could kludge around this with something like:

    if %? == 1 seterror 1

    after your GOSUB call.

    Rex Conn
    JP Software
     

Share This Page