Module:Sandbox/Biggins/ErrorHandling explained

local p = ;

-- Tables taken from the LDSverse module:local bomBooks =

local dcBooks =

local lofBooks =

local pogpBooks =

local bibleBooks =

-- This table holds the titles of the Standard Works themselves, as found on WSlocal standardWorks =

local function xpcallTest(param) if not param then param = "nil" end error("I deliberately threw an error in xpcallTest! (Lua v." .. _VERSION .. ") (ps param was " .. param .. ")") return "It's alll good! " .. param .. "
"end

local function assertTest(param) --assert(false, "I deliberately asserted something I knew to be false!") assert(param, "Oh no: you passed 'false' to assertTest (or no parameter at all)!
") return "Assertion true; everything's a-ok!
"end

local function errorTest(param) error("I deliberately threw an error in errorTest!
")end

local function handler(message) return "Oh I handled it alright! (Message: " .. message .. ")
"end

local function getAliasRows(t) local aliasRows = "" for k,v in pairs(t) do aliasRows = aliasRows .. "| " .. k .. "
| " .. table.concat(v, ", ") .. "
" end return aliasRowsend

local function countKeys(t) local i = 0 for k,v in pairs(t) do i = i+1 end return iend

function p.getBookAliasesWikiTable(standardWork) local wikiTable = class="wikitable sortable mw-collapsible mw-collapsed" |+ class="nowrap" |LDS Template Book Name Aliases ! Standard Work !! Book !! Aliases ]] for sw, bookList in pairs(standardWorks) do wikiTable = wikiTable .. '|-\n|rowspan="' .. countKeys(bookList) .. '"|' .. sw .. "\n" for book, aliases in pairs(bookList) do wikiTable = wikiTable .. "| " .. book .. "\n| " .. table.concat(aliases, ", ") .. "\n|-\n" end end wikiTable = wikiTable .. "|}" return wikiTableend

function p.main(frame) --local params = frame.args --local param = params[1] local r = "" local success, rVal success, rVal = xpcall(xpcallTest, handler, "test param") if (success) then return rVal end r = r .. rVal .. " " success, rVal = pcall(assertTest, param) if (success) then return rVal end r = r .. rVal .. " " success, rVal = pcall(errorTest, param) if (success) then return rVal end r = r .. rVal .. " " return "Sorry, bud, but something went wrong!
" .. rend

return p