<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Modul:Protect/doc - Oʻzgarishlar tarixi</title>
		<link>https://ziyosfera.uz/index.php?title=Modul:Protect/doc&amp;action=history</link>
		<description>Ziyosferadagi mazkur sahifaning oʻzgarishlar tarixi</description>
		<language>uz</language>
		<generator>MediaWiki 1.45.1</generator>
		<lastBuildDate>Wed, 18 Nov 2026 16:20:54 GMT</lastBuildDate>
		<item>
			<title>Programmer: Oʻzbekcha Vikipediyadan import qilindi.</title>
			<link>https://ziyosfera.uz/index.php?title=Modul:Protect/doc&amp;diff=110267&amp;oldid=prev</link>
			<guid isPermaLink="false">https://ziyosfera.uz/index.php?title=Modul:Protect/doc&amp;diff=110267&amp;oldid=prev</guid>
			<description>&lt;p&gt;Oʻzbekcha Vikipediyadan import qilindi.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Yangi sahifa&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Module rating|protected}}&lt;br /&gt;
{{used in system}}&lt;br /&gt;
This [[Help:Lua metamodules|metamodule]] simplifies error handling in other modules. It transforms a function, which may throw an error, into a function, which returns a specified error message in that case.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
 local protect = require(&amp;#039;Module:Protect&amp;#039;)&lt;br /&gt;
 local protectedFunc = protect(func, errFormat, options)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Arguments ===&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;{{code|func}}&amp;#039;&amp;#039;&lt;br /&gt;
*: Function to be transformed.&lt;br /&gt;
* &amp;#039;&amp;#039;{{code|errFormat}}&amp;#039;&amp;#039; (default: {{code|&amp;#039;Error: %s&amp;#039;}})&lt;br /&gt;
*: Custom error message.&lt;br /&gt;
*: Use {{code|&amp;#039;%s&amp;#039;}} to include the message from a caught error.&lt;br /&gt;
* &amp;#039;&amp;#039;{{code|options}}&amp;#039;&amp;#039; – optional table with the following fields:&lt;br /&gt;
** {{code|raw}} (default: false)&lt;br /&gt;
**: If true, then &amp;#039;&amp;#039;{{code|errFormat}}&amp;#039;&amp;#039; will be used as is, otherwise it will be wrapped inside a tag &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** {{code|removeLocation}} (default: true)&lt;br /&gt;
**: If true, removes location information from caught error messages.&lt;br /&gt;
&lt;br /&gt;
=== Return value ===&lt;br /&gt;
&lt;br /&gt;
The resulting {{code|protectedFunc}} is a &amp;#039;&amp;#039;function&amp;#039;&amp;#039;, which calls the original function &amp;#039;&amp;#039;{{code|func}}&amp;#039;&amp;#039;, passing all arguments to it, and returns all its return values. If &amp;#039;&amp;#039;{{code|func}}&amp;#039;&amp;#039; throws an error, the specified error message is returned instead.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local protect = require(&amp;#039;Module:Protect&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
    if not frame.args[1] then&lt;br /&gt;
        error(&amp;#039;missing argument&amp;#039;)&lt;br /&gt;
    end&lt;br /&gt;
    return frame.args[1]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.main = protect(p.main)&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Invoking the main function without arguments will output: &amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;Error: missing argument&amp;lt;/strong&amp;gt;&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{#ifeq:{{SUBPAGENAME}}|sandbox | |&lt;br /&gt;
[[Turkum:Xatolarni boshqarish modullari]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</description>
			<pubDate>Thu, 06 Aug 2026 12:11:45 GMT</pubDate>
			<dc:creator>Programmer</dc:creator>
			<comments>https://ziyosfera.uz/ziyo/Modul_munozarasi:Protect/doc</comments>
		</item>
</channel></rss>