Skip to content

Instantly share code, notes, and snippets.

@fredreichbier
Created August 15, 2010 23:34
Show Gist options
  • Select an option

  • Save fredreichbier/526081 to your computer and use it in GitHub Desktop.

Select an option

Save fredreichbier/526081 to your computer and use it in GitHub Desktop.
HelloException: class extends Exception {
init: super func ~noOrigin
}
UnknownException: class extends Exception {
init: super func ~noOrigin
}
VeryFatalException: class extends Exception {
init: super func ~noOrigin
}
hello: func (i: Int) {
match i {
case 123 => VeryFatalException new("YOU GAVE ME 123") throw()
case 123456 => UnknownException new("You don't know me.") throw()
case => HelloException new("Hello World.") throw()
}
}
tryHello: func (i: Int) {
try {
hello(i)
} catch(e: HelloException) {
"Caught a HelloException: %s" format(e formatMessage() toCString()) print()
} catch e: VeryFatalException {
"Caught an VeryFatalException: %s" format(e formatMessage() toCString()) print()
} catch {
"WTF -- don't know what's that (and that's intended)." println()
}
}
main: func {
tryHello(1337)
tryHello(123)
tryHello(123456)
try {
hello(123)
} catch e: HelloException {
"Caught a HelloException: %s" format(e formatMessage() toCString()) print()
}
}
Caught a HelloException: [HelloException]: Hello World.
Caught an VeryFatalException: [VeryFatalException]: YOU GAVE ME 123
WTF -- don't know what's that (and that's intended).
[VeryFatalException]: YOU GAVE ME 123
./test-exc2[0x80533a3]
./test-exc2[0x80535cf]
./test-exc2[0x805355a]
./test-exc2[0x805362f]
./test-exc2[0x80535a4]
./test-exc2[0x8053647]
./test-exc2[0x804a217]
/lib/libc.so.6(__libc_start_main+0xe6)[0xb756bc76]
./test-exc2[0x8049c11]
[backtrace] zsh: abort ./test-exc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment