File: exceptions3.bsh

package info (click to toggle)
bsh 2.0b4-20
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,224 kB
  • sloc: java: 23,431; xml: 4,500; sh: 139; makefile: 24
file content (38 lines) | stat: -rw-r--r-- 623 bytes parent folder | download | duplicates (11)
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
#!/bin/java bsh.Interpreter

import Exceptions;

source("TestHarness.bsh");

// Catch a checked exception
try { new FileInputStream("/tmp/aksljdflkasd");
} catch ( e ) {
	print(e); flag();
}

// Catch an unchecked exception
try { Exceptions.throwArithmetic();
} catch ( e ) {
	print(e); flag();
}
// Catch an unchecked exception
try { Exceptions.throwRuntime();
} catch ( e ) {
	print(e); flag();
}

// Catch a checked exception
try { Exceptions.throwException();
} catch ( e2 ) {
	print(e2); flag();
}

foo() {
	try { int i=1/0; } catch ( ArithmeticException e ) { flag(); }
}

foo();

assert( flag() == 5 );

complete();