In some cases, your computer may return an error code indicating Lua error checking. There can be several reasons for this error.

g.A Lua error occurs when there is a problem with one of the built-in WoW scripts. Lua error in WoW is usually caused by a faulty add-in or interfaces file. How can I get rid of Lua errors? You can get rid of Lua problems by updating, removing or replacing the add-on manager or script that is causing our own problems.

 

 

g.

This first version was written for Lua 5.0. While still largely relevant to subsequent duplicates, there are a few differences.
The latest revision is for Lua 5. And 3 is available on Amazon and other books shops.
By buying the book, you are also helping Lua support the project.

8.4 – Handling Errors And Exceptions

When you need to deal with bugs in Lua, we need to use the pcall (protected call) reason to wrap your code. You can of course call pcall, which has an anonymous function: if pcall (function ()

For many purposesYou don’t need to write almost all error handlers in Lua.Typically, the application device supports this control.Get all Lua actions from one call from all applications,usually you ask Lua to run to the fairy room.If an error occurs, this phone call will return an error code.and the package can take appropriate action.In a standalone interpreter scriptits main infinite loop only prints the error message, this is a persistent messageand display command prompt and execute all commands.

If you have to face failures in Lua,You have to use the special function pcall (secure call)to encapsulate your primary code.

Suppose you want to run some Lua codeand catchany error time that increased while executing this code.Your first step is to wrap this piece of code infunction; Ask people to call it foo :

Foo () function… and if unexpected_condition then error () end … print (a [i]) – potential error: perhaps ‘a’ is not an array … end

Then customers call foo with call : if pcall (foo) then – run `foo ‘no problem … another – `foo ‘gave an error: take appropriate action … … … … … ! .End

You can of course call. call .reason sufficient for the .anonymous .function: … :. .if .pcall (function. () …. end) in this case … like …

The pcall function calls its first fact in. Todefended this regime,therefore, it practically detects errors during the execution of the function.If there are no mistakes, pcall Possible returns, as well as all values ​​returned by our own call.Otherwise, plus false is returned, the error message.

Despite the name, a specific error message does not usually have to be a string.Every Lua value your family passes in error gets replaced with pcall :

small condition, err = pcall (function () error (code = 121) end) print (error code) -> 121

These mechanisms provide some of what we need to do.Lua Exception Management.weRubbish one with an exception Error andcatch with call …The error detects the type or error encountered.

Copyright © 2003-2004 Jerusalem Roberto. All rights reserved.

Requesting Error Handling

lua error checking

Error handling is very necessary because real operations often require complex operations contained in file operations, database transactions, and online service calls. All

When programming, error correction may always be required. There are two types of errors:

  • Syntax error
  • Runtime error

Syntax Error

Syntax errors occur when various software components such as providers and expressions are misused. A simple example of syntax errors is shown below.

a == 2

As you know, there is only one difference between using a pretty simple equalleg “” and duplication of equal “”. Using one instead of a specific one can lead to proprietary bugs. “Equal” refers to timing, double “equal” refers to comparison. Likewise, we have expressions and search functions with predefined implementation guidelines.

for a = 1.10 seal (s)end

If we run the above diagram, we get the following results: ‘

lua: test2.lua: 2: ‘do’ wait for ‘print’ closer

Syntax errors are much easier to handle than run-time errors because any Lua interpreter catches the error more clearly than a case of read error. From the error above, I can personally easily see that adding a follow a statement before the print statement may be required depending on the Lua structure.

Runtime Error

If there are read errors, the program will run successfully, but run-time errors may occur, mainly due to input errors and improperly managed functions. Below is a simple example of providing runtime errors. enia.

Addition function (a, b) return a + bendadd (10)

When almost everyone builds a program, it builds and runs with confidence. After it expires, a time error is displayed.

lua: test2.lua: 2: three to do arithmetic on your local ‘b’ (null value)Battery Tracking:test2.lua: 2: Using the Add functiontest2.lua: 5: in the main block[What’s this?

This is a runtime error because no more than two variables were passed. The b parameter is expected, and here it is zero, in addition, an error is generated.

Assertion And Error Functions

To deal with bugs, we tend to use features that are both “approved” and therefore buggy. A simple example should be shown below.

local function add (a, b) assert (type (a) == “number”, “a is not a valid number”) assert (type (b) == “number”, “b not number”) return a + bendadd (10)

If we run my program above, we get each of the following error messages. lua: test2.lua: 3: b is no longer a numberBattery Tracking:[C]: essentially “confirm”test2.lua: 3: in the “Add” functiontest2.lua: 6: mostly not[AGAINST] : ?

Error (message [, level]) ends the last protected function that was contacted and returns the message as a complete error message. The function never gets this error. Usually the error adds information about the location of the error when the message is run. The speech level shows how the actual position of the error is determined. At level 1 (the default), the position error type is where each error function was called. The level shows an error at the point where all the called functions were evaluated in error; Etc. Passing area 0 avoids additional associated error location information for sending the message.

Pcall Also Xpcall

lua error checking

To avoid these errors and dealing with Lua programming errors, we need to use the pcall or xpcall functions.

The calls requested by pcall (f, arg1, …) run in protected mode. In particular, if in poundsf, an error occurs, it does not generate an error. It only returns an error state. Below is a simple example using the tested pcall.

Function my function () debby = n / zeroendif pcall (myfunction) then print (“success”)anotherprint (“error”)end

When we run the above program, we stick to the output.

fail

The convenience function xpcall (f, err) requests a function and also defines error handling. No bug in f is propagated; instead fire xpcall the error, call the overboard function with the original error concept, and return a status code.

Function my function () n equals n / nilendMyerrorhandler function (err) print (“ERROR:”, error)endstatus = xpcall (myfunction, myerrorhandler)Print (status)

When we run the above program, we get the following result.

ERROR: test2.lua: 2: trying to run numbers on global ‘n’ (null)Wrong

As a programmer, it is extremely important to make sure that you usually use the correct error handling in your program.rammah that you write. Using error detection can ensure that out-of-range unexpected situations are handled without a doubt without bothering the user of the program.

‘; var adpushup is the same as adpushup || ; adpushup.que = adpushup.que || []; adpushup.que.push (function () repel. triggerad (ad_id); );

 

 

The Lua Assertion is a trick for eliminating budget errors in the Lua programming language. It works with boolean dilemma error handling condition in Lua reason code. It will return the final transactions if the given value is correct, otherwise acknowledge the error signal on the output screen.