summaryrefslogtreecommitdiffhomepage
path: root/vala.html.markdown
diff options
context:
space:
mode:
authorMilo Gilad <milogaccnts@gmail.com>2017-08-26 11:11:22 -0400
committerMilo Gilad <milogaccnts@gmail.com>2017-08-26 11:11:22 -0400
commit374ce84fe9f672b49192ddff2f86d5e3f98d8491 (patch)
treee69a8acc973f3ca9d1c71b0986ed07f6dc4f7ea6 /vala.html.markdown
parent07431ea0d249fedda5ab6dcfcbb825dff6c2c63d (diff)
Added other features: assertions & contract programming & error handling
Diffstat (limited to 'vala.html.markdown')
-rwxr-xr-xvala.html.markdown31
1 files changed, 31 insertions, 0 deletions
diff --git a/vala.html.markdown b/vala.html.markdown
index b9ec558d..93ae6abd 100755
--- a/vala.html.markdown
+++ b/vala.html.markdown
@@ -425,7 +425,38 @@ class Computer<OperatingSystem> : GLib.Object {
var new_computer = new Computer<Linux>();
+/* Other Features */
+
+// Assertions: crash if a statement is not true (at runtime)
+
+bool is_true = true;
+assert(is_true);
+
+// Contract Programming
+
+int contract_demo(int arg1, int arg2) {
+ requires(arg1 > 0 && arg1 < 10) // Notice the lack of semicolon
+ requires(arg2 >= 12)
+ ensures(result >= 0)
+}
+
+// Error Handling
+
+void error_demo(int int_ex) throws GError {
+ if (int_ex != 1) {
+ throw new GError("TEST MESSAGE");
+ }
+}
+void error_demo2() {
+ try {
+ error_demo(0);
+ } catch (GError ge) {
+ stdout.printf("%s\n", ge.message);
+ }
+}
+
```
* More Vala documentation can be found [here](https://valadoc.org/).
* [Alternate construction syntax](https://wiki.gnome.org/Projects/Vala/Tutorial#GObject-Style_Construction) similar to GObject
+* More on contract programming [here](http://en.wikipedia.org/wiki/Contract_programming)
* Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw).