Assertions are a way of breaking out of code when there is an error or an unexpected input.

Some languages throw exceptions and some treat it as a break point.



Task

Show an assertion in your language by asserting that an integer variable is equal to 42.




 
Module Assert {
      \\ This is a global object named Rec
      Global Group Rec {
      Private:
            document doc$="Error List at "+date$(today)+" "+time$(now)+{
            }
      Public:
            lastfilename$="noname.err"
            Module Error(a$) {
                  if a$="" then exit
                  .doc$<="     "+a$+{
                  }
                  flush error
            }
            Module Reset {
                  Clear .doc$
            }
            Module Display {
                  Report  .doc$
            }
            Module SaveIt {
                  .lastfilename$<=replace$("/", "-","Err"+date$(today)+time$(now)+".err")
                  Save.Doc .doc$,.lastfilename$
            }
      }
      Module Checkit {
            Function Error1 (x) {
                  if x<10 then  Print "Normal" : exit 
                  =130   ' error code
            }
            Call Error1(5) 
            Try ok {
                  Call Error1(100)
            } 
            If not Ok then Rec.Error Error$ : Flush Error 
 
            Test "breakpoint A"   ' open Control form, show code as executed, press next or close it
 
            Try {
                  Report "Run this"
                  Error "Hello"
                  Report "Not run this"
            }
            Rec.Error Error$
 
            Module Error1 (x) {
                  if x<10 then  Print "Normal" : exit 
                  Error "Big Error"
            }
            Try ok {
                   Error1 100
            }
            If Error then Rec.Error Error$
      }
      Checkit
      Rec.Display
      Rec.SaveIt
      win "notepad.exe", dir$+Rec.lastfilename$     
}
Assert
 