use concurrent
use system
threadA: func {
Time sleepSec(5)
raise("Exception from ThreadA")
}
threadB: func {
try {
Time sleepSec(6)
} catch (ex: Exception) {
"Handling exception on ThreadB" println()
ex print()
}
}
main: func {
ta := Thread new(threadA)
tb := Thread new(threadB)
ta start()
tb start()
ta wait()
tb wait()
ta free()
tb free()
}
Handling exception on ThreadB
[Exception]: Exception from ThreadA
[fancy backtrace]
0 BacktraceHandler backtrace() in Backtrace (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Backtrace.ooc:26)
1 Exception addBacktrace() in Exception (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Exception.ooc:113)
2 Exception throw() in Exception (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Exception.ooc:138)
3 raise_withClass() in Exception (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Exception.ooc:86)
4 threadA() in trycatchthreadbug (at /home/dwayne/magic-lang-stuff/threadbug/trycatchthreadbug.ooc:7)
5 start_thread() in (at /build/buildd/glibc-2.21/nptl/pthread_create.c:333)
6 clone() in (at /build/buildd/glibc-2.21/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:111)
(SIGSEGV) segmentation fault
[fancy backtrace]
0 BacktraceHandler backtrace() in Backtrace (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Backtrace.ooc:26)
1 Exception getCurrentBacktrace() in Exception (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Exception.ooc:162)
2 _signalHandler() in Exception (at /home/dwayne/magic-lang-stuff/ooc-kean/source/system/Exception.ooc:226)
3 killpg() in (at (null):0)
Example code:
Possible output: