QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: luke on January 27, 2021, 06:53:44 am

Title: $IF VERSION THEN $ERROR
Post by: luke on January 27, 2021, 06:53:44 am
QB64 1.5 will feature a new metacommand and a new pre-compiler value. The below example shows them both:
Code: [Select]
$IF VERSION < 1.5 THEN
    $ERROR Requires QB64 version 1.5 or greater
$END IF

VERSION evaluates to the QB64 compiler version. $ERROR can be used in a $IF block to give a compilation error with a helpful message to the user if the programmer knows they will be using new features. You could also use $ERROR if you program is Windows-only or Linux-only, for instance. VERSION could also be used to implement a section of code two different ways if you're trying to work around differences in behaviour in QB64 versions.

See wiki for further details.
Title: Re: $IF VERSION THEN $ERROR
Post by: SpriggsySpriggs on January 27, 2021, 08:29:01 am
Perfect! I love this idea. You guys are great.
Title: Re: $IF VERSION THEN $ERROR
Post by: RhoSigma on January 28, 2021, 07:45:00 am
Is the build process broken?

Was going to test the $ERROR thing, but the dev-build download is still git e3b9c46 from Jan/27.

Shouldn't it be git f7cd2b2 or 65beb28 from Jan/28 already ??
Title: Re: $IF VERSION THEN $ERROR
Post by: FellippeHeitor on January 28, 2021, 08:02:56 am
Checking. Thanks for pointing it out.
Title: Re: $IF VERSION THEN $ERROR
Post by: RhoSigma on January 28, 2021, 08:12:18 am
Just see, it affects the Windows downloads only.
Title: Re: $IF VERSION THEN $ERROR
Post by: SMcNeill on January 28, 2021, 08:40:15 am
Quick question with all these new error commands:

Since we can generate actual error messages now ( _ERRMESSAGE$, or such, I think), is there some way to set custom messages to go with the codes?

For example, ERROR 5 might give us an error message of “ERROR 5: Illegal Function Call”, but a custom error of 128 would just say, “ERROR 128:”

Is there something like an _CUSTOMERROR$(errNum, errMes$), which an user can use   to set those custom errors?
Title: Re: $IF VERSION THEN $ERROR
Post by: FellippeHeitor on January 28, 2021, 09:18:42 am
If you have a custom error code it’s likely because you have a custom error handler.
Title: Re: $IF VERSION THEN $ERROR
Post by: FellippeHeitor on January 30, 2021, 05:18:22 pm
@SMcNeill I stand corrected, we already have _ASSERT: http://www.qb64.org/wiki/ASSERT

Code: QB64: [Select]
  1. $ASSERTS:CONSOLE
  2.  
  3.     a = INT(RND * 10)
  4.     b$ = myFunc$(a)
  5.     PRINT a, , b$
  6.     _LIMIT 3
  7.  
  8. FUNCTION myFunc$ (value AS SINGLE)
  9.     _ASSERT value > 0, "Value cannot be zero"
  10.     _ASSERT value <= 10, "Value cannot exceed 10"
  11.  
  12.     IF value > 1 THEN plural$ = "s"
  13.     myFunc$ = STRING$(value, "*") + STR$(value) + " star" + plural$ + " :-)"

It's an on-spot error handler which allows for a custom message.