Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#44 cobc 1.1: anything divided by zero... no crash ?

invalid
wont-fix
nobody
None
1
2014-07-29
2012-10-28
acleve
No

Hello,

i am surprised, that cobc 1.1 survives a div by zero.
Even a statement compute ergebnis = 7/0 keeps the program running.
Is this a bug or a feature ?

My code and the result is the following:

cobc (OpenCOBOL) 1.1.0
Copyright (C) 2001-2009 Keisuke Nishida / Roger While
Built Aug 12 2012 14:25:24
Packaged Feb 06 2009 10:30:55 CET

   identification division.
   program-id. divbyzero.
   data division.
   working-storage section.
   01  zaehler        pic 9(2) value 25.
   01  nenner         pic s9(2) value 10.
   01  ergebnis       pic 9(02) value zero.
   procedure division.
   a000-steuer section.
       display "Countdown.. to crash"
       move 10  to nenner
       perform with test after until nenner = -5
         display "Nenner: " nenner
         compute ergebnis = zaehler / nenner
         display "   --> " ergebnis
         compute nenner = nenner - 1
       end-perform
       display "nanu ?"

       continue.
   end-a000-steuer.
       goback.

The output was:

Countdown.. to crash
Nenner: +10
--> 02
Nenner: +09
--> 02
Nenner: +08
--> 03
Nenner: +07
--> 03
Nenner: +06
--> 04
Nenner: +05
--> 05
Nenner: +04
--> 06
Nenner: +03
--> 08
Nenner: +02
--> 12
Nenner: +01
--> 25
Nenner: +00
--> 25
Nenner: -01
--> 25
Nenner: -02
--> 12
Nenner: -03
--> 08
Nenner: -04
--> 06

nanu ?

bye
Alfred

Related

Discussion: For Simon, on bug tracker

Discussion

  • Brian Tiffin
    Brian Tiffin
    2012-10-29

    Yep. To get divide by zero exception use

    DIVIDE zaehler BY nenner GIVING ergebnis
        ON SIZE ERROR
            DISPLAY "Error handler here" END-DISPLAY
        NOT ON SIZE ERROR
            DISPLAY "Success imperative here" END-DISPLAY
    END-DIVIDE
    

    It's COBOL standard not to error out on math, it's the programmers job to explicitly handle illegal computations. Freaked me out the first time too. ;-)

    See http://opencobol.add1tocobol.com/#what-stock-call-library-does-opencobol-offer and scroll down to 4.5.1 for a CBL_ERROR_PROC example showing both exception handling and run time error catchers.

    • status: open --> wont-fix
     
    Last edit: Simon Sobisch 2012-10-29
  • Simon Sobisch
    Simon Sobisch
    2012-10-29

    Alfred, thank you for this question and Brian for this answer. I'll mark it as invalid as it is no bug but more a question. If possible start with a discussion and file a bug if we've seen it is likely one.
    Thank you.

    • milestone: open --> invalid
     
    Last edit: Simon Sobisch 2012-10-29