summaryrefslogtreecommitdiff
path: root/tests/delegates/error-pos.vala
blob: 2e9301a689b26bde1feceee0638bdf77aa3c8c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
errordomain FooError {
	BAR;
}

[CCode (error_pos = 1.8, instance_pos = 1.9)]
delegate string FooFunc (int i) throws FooError;

class Bar {
	[CCode (error_pos = 0.8)]
	public string foo (int i) throws FooError {
		assert (this is Bar);
		return "%i".printf (i);
	}

	[CCode (error_pos = 0.8)]
	public string faz (int i) throws FooError {
		assert (this is Bar);
		throw new FooError.BAR ("%i".printf (i));
	}
}

void foo (FooFunc f) {
	try {
		assert (f (23) == "23");
	} catch {
		assert_not_reached ();
	}
}

void main () {
	try {
		var bar = new Bar ();
		assert (bar.foo (42) == "42");
		foo (bar.foo);
	} catch {
		assert_not_reached ();
	}

	try {
		var bar = new Bar ();
		bar.faz (42);
	} catch (FooError.BAR e) {
		assert (e.message == "42");
	} catch {
		assert_not_reached ();
	}
}