diff --git a/docs/scripting.xml b/docs/scripting.xml index 479e6c8fe..0a3676582 100644 --- a/docs/scripting.xml +++ b/docs/scripting.xml @@ -1256,9 +1256,11 @@ end follows a functional programming paradigm rather than an object oriented programming paradigm. To create an exception handler the nmap.new_try() API method is - used. This method returns a function, which takes a function - as an argument. If the function passed as an argument raises - an exception, then the script execution is aborted and no + used. This method returns a function, which takes a variable + number of arguments, assumed to be the return values of + another function. If an exception is detected in the return + values (the first return value is false), + then the script execution is aborted and no output is produced. Optionally you can pass a function to the new_try() method which will be called if an exception is caught. In this function you can perform @@ -1309,7 +1311,8 @@ try(socket:send(result)) construct consumes the indicator value and returns the remaining values. If the function failed then the second returned value must be a string describing the error - condition. Note that if the value is not nil it is + condition. Note that if the value is not + nil or false it is treated as true so you can return your value in the normal case and return nil, error description if an error occurs. diff --git a/nselib/nmap.luadoc b/nselib/nmap.luadoc index fd85668e1..07cffea78 100644 --- a/nselib/nmap.luadoc +++ b/nselib/nmap.luadoc @@ -153,25 +153,24 @@ function nmap.mutex(object) --- Creates a new exception handler. -- \n\n --- This function returns another function, which itself takes a function as an --- argument. When the returned function is called, it in turn calls the function --- passed to it as an argument, and checks the return value for an error. An --- error is signalled when the first return value of the function is false. If --- there is an error, the script will stop immediately and produce no output. --- And optional handler function can be called before the script is stopped. In --- this function you can perform any clean-up operations, such as closing --- sockets. +-- This function returns another function, an exception handler. The returned +-- function takes a variable number of arguments, which are assumed to be the +-- return values of another function. It checks the return values for an +-- exception, which is signalled when the first return value is false. If there +-- is an exception, the script will stop immediately and produce no output. An +-- optional handler function can be called before the script is stopped. In the +-- error handler function you can perform any clean-up operations, such as +-- closing a socket. -- @param handler Exception handler function (optional). -- @usage -- local result, socket, try, catch\n ---\n +-- \n -- result = ""\n -- socket = nmap.new_socket()\n --- catch = function() \n --- socket:close() \n +-- catch = function()\n +-- socket:close()\n -- end\n -- try = nmap.new_try(catch)\n ---\n -- try(socket:connect(host.ip, port.number))\n -- result = try(socket:receive_lines(1))\n -- try(socket:send(result))