Difference between revisions of "Geterror"

From OpenEUO
Jump to: navigation, search
m (Created page with "== Calling Convention == Call local r[,...] = sl.non([...]) Args a1...aN are of any type Results r1...rN are boolean == Usage Example == local sl = dofile(getinstalldir().....")
 
m (Usage Example)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Calling Convention ==
 
== Calling Convention ==
 
Call
 
Call
  local r[,...] = sl.non([...])
+
  local e = sl.geterror(eref)
 
Args
 
Args
  a1...aN are of any type
+
  eref is a number
 
Results
 
Results
  r1...rN are boolean
+
  e is a table with key:val pair _type:'table:exception' defined
  
 
== Usage Example ==
 
== Usage Example ==
  
 
  local sl = dofile(getinstalldir()..'/lib/simplelib.lua')
 
  local sl = dofile(getinstalldir()..'/lib/simplelib.lua')
  non  = sl.non
+
  sl.slredirect('in')
  null = sl.null
+
  local f = function() local a  = {} a = a + 1 end
  local a,b,c,d = non(false,nil,null,0)
+
  local h = function(eref)
  print(a)
+
  local le = eref
print(b)
+
  if type(le) == 'string' then
  print(c)
+
    error(le,1)
  print(d)
+
  end
 +
end
 +
local c,d = sl.try(f,h)
 +
  print(tostring(c))
 +
  print(tostring(d))
 +
  print(tostring(sl.geterror(d)._errmsg))
  
  --> 'false'
+
  --> nil
--> 'true'
+
    1
--> 'true'
+
    a try() handler function raised an unknown exception.
--> 'false'
+
    At: ...\scripts\test00.lua:11.
 +
    Exception text: ...\scripts\test00.lua:7: attempt to perform arithmetic on local 'a' (a table value).
  
 
== Description ==
 
== Description ==
  
Tests each supplied argument as to whether it is [[nil]] or [[null]]If so, then non returns true for that value, otherwise false. non returns the same number of values as the number of arguments it accepted.
+
geterror returns the recorded error table of a detected error when given a valid numeric error reference, eref.  An error table has the following fields:
 +
 
 +
field    : description
 +
_type      'table:exception'
 +
_errid      Same as the argument provided to geterror. Numeric.
 +
  _errname    Name provided for the error, or 'SL unknown error'.
 +
_errmsg    String of descriptive text associated with the error.
 +
_probe      A table of stack information tables for internal use.
  
 
== Upon Error ==
 
== Upon Error ==
  
If non receives no arguments, then it returns a single nil value.
+
If geterror receives no arguments, or a non-numeric argument, or the argument is out of range, then it returns a single [[nil]] value.
  
 
== See Also ==
 
== See Also ==
 +
 +
* [http://www.easyuo.com/openeuo/wiki/index.php/Simplelib simplelib]
  
 
* [[ERR]]
 
* [[ERR]]

Latest revision as of 16:18, 2 November 2010

Calling Convention

Call

local e = sl.geterror(eref)

Args

eref is a number

Results

e is a table with key:val pair _type:'table:exception' defined

Usage Example

local sl = dofile(getinstalldir()..'/lib/simplelib.lua')
sl.slredirect('in')
local f = function() local a  = {} a = a + 1 end
local h = function(eref)
  local le = eref
  if type(le) == 'string' then
    error(le,1)
  end
end
local c,d = sl.try(f,h)
print(tostring(c))
print(tostring(d))
print(tostring(sl.geterror(d)._errmsg))
--> nil
    1
    a try() handler function raised an unknown exception.
    At: ...\scripts\test00.lua:11.
    Exception text: ...\scripts\test00.lua:7: attempt to perform arithmetic on local 'a' (a table value).

Description

geterror returns the recorded error table of a detected error when given a valid numeric error reference, eref. An error table has the following fields:

field     : description
_type       'table:exception'
_errid      Same as the argument provided to geterror. Numeric.
_errname    Name provided for the error, or 'SL unknown error'.
_errmsg     String of descriptive text associated with the error.
_probe      A table of stack information tables for internal use.

Upon Error

If geterror receives no arguments, or a non-numeric argument, or the argument is out of range, then it returns a single nil value.

See Also