<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.wikiw.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3ATryError</id>
	<title>模块:TryError - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.wikiw.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3ATryError"/>
	<link rel="alternate" type="text/html" href="https://www.wikiw.cn/index.php?title=%E6%A8%A1%E5%9D%97:TryError&amp;action=history"/>
	<updated>2026-04-08T20:08:44Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://www.wikiw.cn/index.php?title=%E6%A8%A1%E5%9D%97:TryError&amp;diff=2313&amp;oldid=prev</id>
		<title>imported&gt;Xiplus-abot：​已更改“Module:TryError”的保护等级：高風險模板：8426引用&lt;!-- 機器人3 --&gt;（[编辑=仅允许模板编辑员和管理员]（无限期）[移动=仅允许模板编辑员和管理员]（无限期））</title>
		<link rel="alternate" type="text/html" href="https://www.wikiw.cn/index.php?title=%E6%A8%A1%E5%9D%97:TryError&amp;diff=2313&amp;oldid=prev"/>
		<updated>2020-08-17T04:14:41Z</updated>

		<summary type="html">&lt;p&gt;已更改“&lt;a href=&quot;/index.php?title=%E6%A8%A1%E5%9D%97:TryError&quot; title=&quot;模块:TryError&quot;&gt;Module:TryError&lt;/a&gt;”的保护等级：高風險模板：8426引用&amp;lt;!-- &lt;a href=&quot;/index.php?title=%E7%94%A8%E6%88%B7:Xiplus-abot/task/3&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;用户:Xiplus-abot/task/3（页面不存在）&quot;&gt;機器人3&lt;/a&gt; --&amp;gt;（[编辑=仅允许模板编辑员和管理员]（无限期）[移动=仅允许模板编辑员和管理员]（无限期））&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p={}&lt;br /&gt;
local lib_arg={}&lt;br /&gt;
local yesno = {}&lt;br /&gt;
function p._message(err_obj)&lt;br /&gt;
	local err_array = err_obj&lt;br /&gt;
	local body = &amp;#039;&amp;#039;&lt;br /&gt;
	if type(err_obj.message) == type(&amp;quot;string&amp;quot;) then err_array={err_obj} end&lt;br /&gt;
	for i=1,#err_array do body = body .. err_array[i].message or &amp;#039;&amp;#039;end&lt;br /&gt;
	return body&lt;br /&gt;
end&lt;br /&gt;
function p._throw(err_obj)&lt;br /&gt;
	local err_array = err_obj&lt;br /&gt;
	local body = &amp;#039;&amp;#039;&lt;br /&gt;
	if type(err_obj.message) == type(&amp;quot;string&amp;quot;) then err_array={err_obj} end&lt;br /&gt;
	for i=1,#err_array do&lt;br /&gt;
		local message = err_array[i].message or &amp;#039;&amp;#039;&lt;br /&gt;
	    if mw.text.trim(message) == &amp;#039;&amp;#039; then message = error(&amp;#039;没有指定的錯誤-{zh-cn:信息; zh-tw:資訊}-&amp;#039;, 2) end&lt;br /&gt;
	    message = tostring(message)&lt;br /&gt;
	    local tag = &amp;#039;strong&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	    -- Generate the html.&lt;br /&gt;
	    local root = mw.html.create(tag)&lt;br /&gt;
	    for j=1,#err_array[i].types do&lt;br /&gt;
	    	root:addClass(err_array[i].types[j])&lt;br /&gt;
	    end&lt;br /&gt;
	    root&lt;br /&gt;
	        :addClass(&amp;#039;error&amp;#039;)&lt;br /&gt;
	        :wikitext(message)&lt;br /&gt;
		body = body .. tostring(root)&lt;br /&gt;
	end&lt;br /&gt;
	return body&lt;br /&gt;
end&lt;br /&gt;
function p._constructErrorFromArg(str)&lt;br /&gt;
	local error_array = {}&lt;br /&gt;
	mw.ustring.gsub(str,&amp;quot;([^%(]+)%(([^%)]*)%)&amp;quot;,function(name,para)&lt;br /&gt;
		error_array[#error_array + 1] = {[&amp;#039;message&amp;#039;]=para,[&amp;#039;types&amp;#039;]=mw.text.split(name,&amp;#039;,&amp;#039;)or {name} }&lt;br /&gt;
		return name..para &lt;br /&gt;
	end)&lt;br /&gt;
	return error_array&lt;br /&gt;
end&lt;br /&gt;
function p._constructError(str)&lt;br /&gt;
	local result={[&amp;#039;message&amp;#039;]=&amp;#039;&amp;#039;,[&amp;#039;types&amp;#039;]={}}&lt;br /&gt;
	if mw.text.trim(str or &amp;#039;&amp;#039;) == &amp;quot;&amp;quot; then return {[&amp;#039;message&amp;#039;]=&amp;#039;&amp;#039;,[&amp;#039;types&amp;#039;]={&amp;#039;unknown&amp;#039;}} end&lt;br /&gt;
	local error_tags = {&amp;#039;strong&amp;#039;, &amp;#039;span&amp;#039;, &amp;#039;p&amp;#039;, &amp;#039;div&amp;#039;}&lt;br /&gt;
    for i=1,#error_tags do&lt;br /&gt;
    	local check_tag = error_tags[i]:gsub(&amp;#039;^(.-)$&amp;#039;,&amp;#039;&amp;lt;%1[^&amp;gt;]*&amp;gt;(.-)&amp;lt;/%1&amp;gt;&amp;#039;)&lt;br /&gt;
    	local find_msg = &amp;#039;&amp;lt;&amp;#039;&lt;br /&gt;
    	mw.ustring.gsub(str,check_tag,function(check_msg)find_msg=check_msg end)&lt;br /&gt;
    	find_msg = mw.text.trim(find_msg)&lt;br /&gt;
    	if mw.ustring.sub(find_msg,1,1) ~= &amp;#039;&amp;lt;&amp;#039; then&lt;br /&gt;
    		result.message = find_msg&lt;br /&gt;
    		break&lt;br /&gt;
    	end&lt;br /&gt;
    end&lt;br /&gt;
    local error_attritube = {&amp;#039;class&amp;#039;, &amp;#039;id&amp;#039;}&lt;br /&gt;
    local typemap={[&amp;#039;error&amp;#039;]=1}&lt;br /&gt;
    for i=1,#error_attritube do&lt;br /&gt;
    	local check_tag_dstr = error_attritube[i]:gsub(&amp;#039;^(.-)$&amp;#039;,&amp;#039;%1=&amp;quot;([^&amp;quot;]+)&amp;quot;&amp;#039;)&lt;br /&gt;
    	local check_tag_sstr = error_attritube[i]:gsub(&amp;#039;^(.-)$&amp;#039;,&amp;quot;%1=&amp;#039;([^&amp;#039;]+)&amp;#039;&amp;quot;)&lt;br /&gt;
    	local check_tag_pstr = error_attritube[i]:gsub(&amp;#039;^(.-)$&amp;#039;,&amp;quot;%1=([^%%s]+)&amp;quot;)&lt;br /&gt;
    	local dstr,sstr,pstr = &amp;#039;&amp;#039;,&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&lt;br /&gt;
    	mw.ustring.gsub(str,check_tag_dstr,function(check_msg)dstr=mw.text.trim(check_msg)end)&lt;br /&gt;
    	mw.ustring.gsub(str,check_tag_sstr,function(check_msg)sstr=mw.text.trim(check_msg)end)&lt;br /&gt;
    	mw.ustring.gsub(str,check_tag_pstr,function(check_msg)pstr=mw.text.trim(check_msg)end)&lt;br /&gt;
    	local pstr_ch = mw.ustring.sub(pstr,1,1)&lt;br /&gt;
    	if pstr_ch ~= &amp;#039;&amp;quot;&amp;#039; and pstr_ch ~= &amp;quot;&amp;#039;&amp;quot; then &lt;br /&gt;
    		if mw.text.trim(pstr) ~= &amp;quot;&amp;quot; then&lt;br /&gt;
    			typemap[pstr] = 1&lt;br /&gt;
    		end&lt;br /&gt;
    	end&lt;br /&gt;
    	local sdstr = mw.ustring.gsub(dstr .. &amp;#039; &amp;#039; .. sstr, &amp;#039;%s+&amp;#039;, &amp;#039; &amp;#039;)&lt;br /&gt;
    	local sdarr = mw.text.split(sdstr,&amp;#039; &amp;#039;)&lt;br /&gt;
    	for _,class_name in ipairs(sdarr) do&lt;br /&gt;
    		if mw.text.trim(class_name) ~= &amp;quot;&amp;quot; then&lt;br /&gt;
    			typemap[class_name] = 1&lt;br /&gt;
    		end&lt;br /&gt;
    	end&lt;br /&gt;
    end&lt;br /&gt;
    for class_name,_ in pairs(typemap) do&lt;br /&gt;
    	if type(result.types) ~= type{&amp;quot;table&amp;quot;} then result.types={} end&lt;br /&gt;
    	result.types[#result.types + 1]=class_name&lt;br /&gt;
    end&lt;br /&gt;
    local getFrommsg = mw.text.split(result.message,&amp;quot;[:：︓﹕。%s]&amp;quot;)&lt;br /&gt;
    result.types[#result.types + 1]=mw.ustring.gsub(getFrommsg[1],&amp;quot;&amp;lt;[^&amp;gt;]+&amp;gt;&amp;quot;,&amp;quot;&amp;quot;)&lt;br /&gt;
    result.types[#result.types]=mw.ustring.gsub(result.types[#result.types],&amp;#039;[“&amp;quot;「][^”&amp;quot;」]-[”&amp;quot;」]&amp;#039;,&amp;#039;&amp;#039;)&lt;br /&gt;
    &lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
function p.try(frame)&lt;br /&gt;
	local args, working_frame&lt;br /&gt;
    if frame == mw.getCurrentFrame() then&lt;br /&gt;
        -- We&amp;#039;re being called via #invoke. The args are passed through to the module&lt;br /&gt;
        -- from the template page, so use the args that were passed into the template.&lt;br /&gt;
        if lib_arg.getArgs == nil then lib_arg = require(&amp;#039;Module:Arguments&amp;#039;) end&lt;br /&gt;
        args = lib_arg.getArgs(frame, {&lt;br /&gt;
        	parentFirst=true,&lt;br /&gt;
        	trim = false,&lt;br /&gt;
			removeBlanks = false&lt;br /&gt;
        })&lt;br /&gt;
        working_frame = frame&lt;br /&gt;
    else&lt;br /&gt;
        -- We&amp;#039;re being called from another module or from the debug console, so assume&lt;br /&gt;
        -- the args are passed in directly.&lt;br /&gt;
        args = frame&lt;br /&gt;
        working_frame = mw.getCurrentFrame()&lt;br /&gt;
        if type(args) ~= type({}) then args = {frame} end&lt;br /&gt;
    end&lt;br /&gt;
    local input_try = args[1] or args[&amp;#039;1&amp;#039;]&lt;br /&gt;
    local multi_catch = false&lt;br /&gt;
    if (args.multi or &amp;#039;&amp;#039;) ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		if type(yesno) ~= type(tonumber) then yesno = require(&amp;#039;Module:Yesno&amp;#039;) end&lt;br /&gt;
		multi_catch = yesno(args.multi or &amp;#039;no&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local preprocess = false&lt;br /&gt;
    if (args.preprocess or &amp;#039;&amp;#039;) ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		if type(yesno) ~= type(tonumber) then yesno = require(&amp;#039;Module:Yesno&amp;#039;) end&lt;br /&gt;
		preprocess = yesno(args.preprocess or &amp;#039;no&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
    local if_errorcall = tonumber(mw.getCurrentFrame().args.if_errorcall or &amp;#039;0&amp;#039;) or 0&lt;br /&gt;
    local catch_list = {}&lt;br /&gt;
    local default_catch = {[&amp;quot;value&amp;quot;]=&amp;quot;{{{throw|error(未處理的例外狀況:)}}}{{{throw}}}&amp;quot;, [&amp;quot;exception&amp;quot;]={} }&lt;br /&gt;
    for key,value in pairs(args) do&lt;br /&gt;
    	local argname = mw.ustring.lower(tostring(key))&lt;br /&gt;
    	local exception_data ,checker = mw.ustring.gsub(argname,&amp;#039;^%s*catch%s*%((.-)%)%s*$&amp;#039;,&amp;#039;%1&amp;#039;)&lt;br /&gt;
    	if checker &amp;gt; 0 then&lt;br /&gt;
    		catch_list[#catch_list+1] = {[&amp;quot;value&amp;quot;]=value, [&amp;quot;exception&amp;quot;]=(mw.text.split(exception_data,&amp;#039;,&amp;#039;) or {exception_data})}&lt;br /&gt;
    	elseif mw.text.trim(argname) == &amp;#039;catch&amp;#039; then&lt;br /&gt;
    		default_catch.value=value&lt;br /&gt;
    	end&lt;br /&gt;
    end&lt;br /&gt;
    catch_list[#catch_list+1]=default_catch&lt;br /&gt;
    &lt;br /&gt;
    local find_error = &amp;#039; &amp;#039; .. (input_try or &amp;#039;&amp;#039;) .. &amp;#039; &amp;#039;--/^...$/&lt;br /&gt;
    local error_tags = {&amp;#039;strong&amp;#039;, &amp;#039;span&amp;#039;, &amp;#039;p&amp;#039;, &amp;#039;div&amp;#039;}&lt;br /&gt;
    local exceptions = {}&lt;br /&gt;
&lt;br /&gt;
    for i=1,#error_tags do&lt;br /&gt;
    	local check_tag = error_tags[i]:gsub(&amp;#039;^(.-)$&amp;#039;,&amp;#039;&amp;lt;%1[^&amp;gt;]+error.-&amp;lt;/%1&amp;gt;&amp;#039;)&lt;br /&gt;
    	find_error = mw.ustring.gsub(find_error,check_tag,function(exception)&lt;br /&gt;
    		exceptions[#exceptions + 1] = p._constructError(exception)&lt;br /&gt;
    	return&amp;#039;&amp;#039;end)&lt;br /&gt;
    end&lt;br /&gt;
	find_error = mw.text.trim(find_error)&lt;br /&gt;
	if #exceptions&amp;lt;=0 and if_errorcall &amp;gt; 0 then&lt;br /&gt;
		exceptions[#exceptions + 1] = {[&amp;#039;message&amp;#039;]=&amp;#039;其他錯誤&amp;#039;,[&amp;#039;types&amp;#039;]={&amp;#039;error&amp;#039;}}&lt;br /&gt;
	end&lt;br /&gt;
	if #exceptions&amp;lt;=0 and if_errorcall &amp;lt;= 0 then&lt;br /&gt;
		if preprocess == true then return working_frame:preprocess(input_try) end&lt;br /&gt;
		return input_try&lt;br /&gt;
	end&lt;br /&gt;
	local body = &amp;#039;&amp;#039;&lt;br /&gt;
	local catched = false&lt;br /&gt;
	for i=1,#catch_list do&lt;br /&gt;
		local current_catch = catch_list[i]&lt;br /&gt;
		local found = false&lt;br /&gt;
		local exception_obj = nil&lt;br /&gt;
		for j=1,#current_catch.exception do&lt;br /&gt;
			for k=1,#exceptions do&lt;br /&gt;
				for ke=1,#exceptions[k].types do&lt;br /&gt;
					local to_check_ex = mw.ustring.lower(exceptions[k].types[ke])&lt;br /&gt;
					local to_check_pattern = mw.text.trim(mw.ustring.lower(current_catch.exception[j]))&lt;br /&gt;
					local check_eq = to_check_ex == to_check_pattern&lt;br /&gt;
					local check_isregexp = false&lt;br /&gt;
					if mw.ustring.sub(to_check_pattern,1,1) == &amp;#039;/&amp;#039; and mw.ustring.sub(to_check_pattern,-1,-1) == &amp;#039;/&amp;#039; then&lt;br /&gt;
						to_check_pattern = mw.ustring.sub(to_check_pattern,2,-2)&lt;br /&gt;
						if check_eq ~= true then&lt;br /&gt;
							xpcall( function() &lt;br /&gt;
								local check_req = mw.ustring.find(to_check_ex, to_check_pattern)&lt;br /&gt;
								if check_req then check_eq = true end&lt;br /&gt;
							end , function() end )&lt;br /&gt;
						end&lt;br /&gt;
					end&lt;br /&gt;
					if check_eq == true then&lt;br /&gt;
						found = true&lt;br /&gt;
						exception_obj = exceptions[k]&lt;br /&gt;
						break&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				if found == true then break end&lt;br /&gt;
			end&lt;br /&gt;
			if found == true then break end&lt;br /&gt;
		end&lt;br /&gt;
		if #exceptions &amp;gt; 0 and i==#catch_list then &lt;br /&gt;
			exception_obj=exceptions[1]&lt;br /&gt;
			found = true&lt;br /&gt;
		end&lt;br /&gt;
		if i==#catch_list then &lt;br /&gt;
			if catched==true then&lt;br /&gt;
				catch_list[#catch_list].value = &amp;quot;{{{throw}}}&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if found == true and exception_obj then&lt;br /&gt;
			local catch_data = catch_list[i].value&lt;br /&gt;
			catch_data = mw.ustring.gsub(catch_data, &amp;#039;%{%{%{%s*throw%s*(|?[^%}]*)%}%}%}&amp;#039;,function(str)&lt;br /&gt;
				local use_old_error = false&lt;br /&gt;
				local input_throw = mw.text.trim(str)&lt;br /&gt;
				if input_throw == &amp;#039;&amp;#039; then use_old_error = true end&lt;br /&gt;
				if mw.ustring.sub(input_throw,1,1) == &amp;#039;|&amp;#039; then&lt;br /&gt;
					input_throw=mw.text.trim(mw.ustring.sub(input_throw,2,-1))&lt;br /&gt;
					if input_throw == &amp;#039;&amp;#039; then return &amp;#039;&amp;#039; end&lt;br /&gt;
					return p._throw(p._constructErrorFromArg(input_throw))&lt;br /&gt;
				elseif use_old_error == true then&lt;br /&gt;
					if i==#catch_list then return p._throw(exceptions) end&lt;br /&gt;
					return p._throw(exception_obj)&lt;br /&gt;
				end&lt;br /&gt;
				return &amp;#039;{{{throw&amp;#039; .. str .. &amp;#039;}}}&amp;#039;&lt;br /&gt;
			end)&lt;br /&gt;
			catch_data = mw.ustring.gsub(catch_data, &amp;#039;%{%{%{%s*message%s*(|?[^%}]*)%}%}%}&amp;#039;,function(str)&lt;br /&gt;
				local use_old_error = false&lt;br /&gt;
				local input_throw = mw.text.trim(str)&lt;br /&gt;
				if input_throw == &amp;#039;&amp;#039; then use_old_error = true end&lt;br /&gt;
				if mw.ustring.sub(input_throw,1,1) == &amp;#039;|&amp;#039; then&lt;br /&gt;
					input_throw=mw.text.trim(mw.ustring.sub(input_throw,2,-1))&lt;br /&gt;
					if input_throw == &amp;#039;&amp;#039; then return &amp;#039;&amp;#039; end&lt;br /&gt;
					return p._message(p._constructErrorFromArg(input_throw))&lt;br /&gt;
				elseif use_old_error == true then&lt;br /&gt;
					if i==#catch_list then return p._message(exceptions) end&lt;br /&gt;
					return p._message(exception_obj)&lt;br /&gt;
				end&lt;br /&gt;
				return &amp;#039;{{{message&amp;#039; .. str .. &amp;#039;}}}&amp;#039;&lt;br /&gt;
			end)&lt;br /&gt;
			body = body .. catch_data&lt;br /&gt;
			if multi_catch==true then &lt;br /&gt;
				catched = true&lt;br /&gt;
			else&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	body = mw.ustring.gsub(body, &amp;#039;%{%{%{%s*[Nn][Oo]%s*[Ee][Rr][Rr][Oo][Rr]%s*(|?[^%}]*)%}%}%}&amp;#039;,function(str)&lt;br /&gt;
		local use_old_error = false&lt;br /&gt;
		local input_throw = mw.text.trim(str)&lt;br /&gt;
		if input_throw == &amp;#039;&amp;#039; then use_old_error = true end&lt;br /&gt;
		if mw.ustring.sub(input_throw,1,1) == &amp;#039;|&amp;#039; then&lt;br /&gt;
			input_throw=mw.text.trim(mw.ustring.sub(input_throw,2,-1))&lt;br /&gt;
			if mw.ustring.trim(input_throw) == &amp;#039;&amp;#039; then return &amp;#039;&amp;#039; end&lt;br /&gt;
			if mw.ustring.trim(find_error) == &amp;#039;&amp;#039; then return input_throw end&lt;br /&gt;
			return find_error&lt;br /&gt;
		elseif use_old_error == true then return find_error end&lt;br /&gt;
		return &amp;#039;{{{no error&amp;#039; .. str .. &amp;#039;}}}&amp;#039;&lt;br /&gt;
	end)&lt;br /&gt;
	if preprocess == true then return working_frame:preprocess(body) end&lt;br /&gt;
    return body&lt;br /&gt;
end&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Xiplus-abot</name></author>
	</entry>
</feed>