Wing Programming Language
Wing Next

Error handling

When your code is incorrect, Wing may display errors. There are three times of errors:
  • warnings (in yellow): these tell you that your code contains an error but is still able to run. However, it may become more unstable: a warning can lead to more warnings.
  • errors (in red): these tell you that a fatal error occured with your code and that it cannot continue running.
  • deprecations (in cyan): these tell you that you are using a feature that is not supported anymore and will be removed in a future version of Wing.

Error synopsis

An error generally looks like this:
Wing: Warning: Attempted to import from a function context
* at local line 1, global line 33
* in function stuff
* in file /my/code/test.wing
> 33 #include /some/path/to/a/file.wing
You are presented with:
  • first, the type of error and what the error is;
  • on the next line, where in the current function (local line) and in the current file (global line, or just line) the error occured
  • then, if any, the function that was being executed when this error occured
  • next, the path to the file that was being executed
You also get the contents of the line the error occured on, including the previous (if any) and next (if any) line. This makes it easier to locate the error in your code.
Using Wing Creator, you can get a better view at errors in your code.
Deprecations show a slightly different error message, meant to be shorter than the message for regular errors, since deprecations are not extremely important at run time:
Wing: Deprecation: This feature is deprecated and will be removed in Wing 3 (line 36 in /my/code/test.wing)

Strict mode

The default behavior for errors (which is simply showing them and continuing execution) may not be convenient in some cases. For these cases, you may want to enable strict mode.
Strict mode essentially makes all warnings errors, meaning any warning in your code will now stop execution after showing the error message.
To enable strict mode, you simply need to insert the following code in your program:
Note, however, that once enabled, strict mode will be effective in all functions and all files running; and that strict mode cannot be disabled once it is enabled.
Also note that strict mode does not affect deprecations, and that deprecations are simply for notice purposes.

Dealing with deprecations

As Wing is an ever evolving language, some features can be removed (or their behavior can be changed) for convenience.
For example, let's say you used the following code to read a file:
supercoolfilereader_open /path/to/file.txt
But in a new version of the supercoolfilereader library, these two lines of code can be replaced with:
supercoolfilereader_read /path/to/file.txt
The developers of the supercoolfilereader library may make the supercoolfilereader_file_read function deprecated, which serves two purposes:
  • letting developers know there is a better way of doing what they are doing;
  • informing developers that the legacy function they are using may be removed in a future version
To work around deprecations without having to change your code, you can stay on an older version of Wing. This, however, has a lot of drawbacks.
Using an older (and unsupported) version of Wing is not and will never be supported. By doing so, you expose users of your program to unnecessary security risks. Always update your code to work with new versions of Wing when possible.

Throwing errors

While this should not be necessary in most cases, Wing gives you the option to make your own warnings, errors or deprecations directly from your code.
This is particularly useful if you are working on a library.
To throw errors, you need to start a line with ?. What you put after determines which type of error you are going to throw:
  • ? (nothing after) throws a regular warning
  • ?? throws an error
  • ?! throws a deprecation
For example:
? That's not nice -- Will show a warning
?? That's really not nice -- Will show an error
?! This is old! -- Will show a deprecation

What does Syntax error mean?

Every time Wing encounters an unrecognised line of code in your program, it will display a "Syntax error" warning. This warning is not very descriptive, isn't it?
Using Wing Creator, you can get more details about a syntax error and what exactly is causing it, including a potential fix.