Announcement

Collapse
No announcement yet.

error handling

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • error handling

    I have to create a local error handling routine with resume.
    Is it possible to have one byte per statement added only in
    the sub that the local handler refers to? I cannot just use
    $event off outside the sub because i need other events to be
    trapped and there is a global error handler (without resume)

    ------------------

  • #2
    Can you tell us what errors do you actually want to trap in that particular sub/function?

    Note that unless you are already using $ERROR ALL OFF (or are using the default IDE options of OFF), then you already have the additional overhead of error testing code added to your compiled app (see $ERROR in the documentation).

    BTW, I'm not clear that $EVENT OFF affects the generation of error checking code, since error testing and event trapping are separate entities. I'll check with R&D.




    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Confirmed: $EVENT does not affect the generation of error trapping code as specified with $ERROR.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Here are the details.

        I use $error all on because the program is really big (so it
        may have many bugs) and it is still being developed.

        I have a global error trapping routine which just displays
        a message, the error number and location and writes some data
        to disk. These data may be used for debugging then.

        I have a sub that sends data either to disk or to printer.
        I want to make this sub safe against printer errors (timeout,
        paper out, etc.). So I wrote a local error handler which
        checks for error number. If the error is not related to
        printer, then control is transferred to the global handler.
        In case of printer error, the user is asked what to do: cancel
        printing or retry (after he or she adds paper, turns the printer
        on, or whatever is needed). The retry is accomplished by RESUME
        statement.

        According to the PowerBasic Refernce Guide, the RESUME adds
        one byte to the EXE file for each statement. This adds as much
        as 10 kB to my program. However, my RESUME is in a local
        handler. Is it possible to force the compiler to add one byte
        per each statement of the sub rather than for each statement
        of the whole program?

        I hope that i was clear enough this time. Sorry for bad English.

        ------------------

        Comment


        • #5
          As I understand it, this is not possible at this time. Sorry!

          You may need to rework your printing and local error handler sub/function more, in order to eliminate the problem.

          For example, by writing the whole print job to a temporary disk file, and then the actual printing code can be handled in a loop that reads from the file and sends it to the printer. This way you may be able to use RESUME <label> instead of a plain RESUME.

          Another idea would be to switch off the global error handler inside that sub/function (ON LOCAL ERROR RESUME NEXT) and query the state of ERR after each critical statement. Then you can "manually" handle errors on a case-by-case basis, possibly with a subroutine inside the sub/function.

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected].com</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Another way is to separately compile the code where you want the error-trapping code by putting it in a PBU file.

            As long as you use ON ERROR or RESUME in the PBU module, the code is generated; if you don't use these verbs, it ain't.

            MCM




            ------------------
            Michael Mattias
            Racine WI USA
            [email protected]
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Great thinking Michael!

              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment

              Working...
              X