/lua_lanes/tests/error.lua
Lua | 47 lines | 25 code | 10 blank | 12 comment | 1 complexity | 3054be46b5264d9dac6e18015532bbcd MD5 | raw file
Possible License(s): Zlib, BSD-3-Clause, CC0-1.0, GPL-3.0, GPL-2.0, CPL-1.0, MPL-2.0-no-copyleft-exception, LGPL-2.0, LGPL-2.1, LGPL-3.0, 0BSD, Cube
- --
- -- Error reporting
- --
- -- Note: this code is supposed to end in errors; not included in 'make test'
- --
-
- local lanes = require "lanes".configure()
-
- local function lane()
-
- local subf= function() -- this so that we can see the call stack
- error "aa"
- --error({})
- --error(error)
- end
- local subf2= function()
- subf()
- end
- subf2()
- end
-
- local function cleanup(err)
- end
-
- local lgen = lanes.gen("*", { --[[finalizer=cleanup]] }, lane)
-
- ---
- io.stderr:write( "\n** Error catching **\n" )
- --
- local h= lgen()
- local _,err,stack= h:join() -- wait for the lane (no automatic error propagation)
-
- if err then
- assert( type(stack)=="table" ) -- only true if lanes was compiled with ERROR_FULL_STACK == 1
- io.stderr:write( "Lane error: "..tostring(err).."\n" )
-
- io.stderr:write( "\t", table.concat(stack,"\n\t"), "\n" );
- end
-
- ---
- io.stderr:write( "\n** Error propagation **\n" )
- --
- local h2= lgen()
- local _= h2[0]
- assert(false) -- does NOT get here
-
- --never ends