PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/lanes/error.lua

http://luapack.googlecode.com/
Lua | 47 lines | 26 code | 10 blank | 11 comment | 1 complexity | 2bfdbc87c0d033872dab39fe863833d3 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, ISC
  1. --
  2. -- Error reporting
  3. --
  4. -- Note: this code is supposed to end in errors; not included in 'make test'
  5. --
  6. require "lanes"
  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" )
  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