PageRenderTime 57ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/lua_lanes/tests/error.lua

https://bitbucket.org/xixs/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
  1. --
  2. -- Error reporting
  3. --
  4. -- Note: this code is supposed to end in errors; not included in 'make test'
  5. --
  6. local lanes = require "lanes".configure()
  7. local function lane()
  8. local subf= function() -- this so that we can see the call stack
  9. error "aa"
  10. --error({})
  11. --error(error)
  12. end
  13. local subf2= function()
  14. subf()
  15. end
  16. subf2()
  17. end
  18. local function cleanup(err)
  19. end
  20. local lgen = lanes.gen("*", { --[[finalizer=cleanup]] }, lane)
  21. ---
  22. io.stderr:write( "\n** Error catching **\n" )
  23. --
  24. local h= lgen()
  25. local _,err,stack= h:join() -- wait for the lane (no automatic error propagation)
  26. if err then
  27. assert( type(stack)=="table" ) -- only true if lanes was compiled with ERROR_FULL_STACK == 1
  28. io.stderr:write( "Lane error: "..tostring(err).."\n" )
  29. io.stderr:write( "\t", table.concat(stack,"\n\t"), "\n" );
  30. end
  31. ---
  32. io.stderr:write( "\n** Error propagation **\n" )
  33. --
  34. local h2= lgen()
  35. local _= h2[0]
  36. assert(false) -- does NOT get here
  37. --never ends