summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraalatchm <aalatchm@jamailca.com>2011-03-30 13:41:45 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2011-03-31 12:06:06 +0000
commitaec67b4e608465017ad67665f8cd1f37ae35d6cc (patch)
tree7f19cf91bb519dd350c448439fd505a383bd53c7
parent7882795d10fc28a696a4784d24fbb2990a5e5707 (diff)
downloadposixtz-0.3.tar.bz2
posixtz-0.3.tar.xz
Modified parse() function to avoid throwing exceptions.v0.3
Lua 'error()' function was previously used, but this throws exceptions. If the user does not catch the exceptions, then his code will exit. This commit replaces the 'error()' function with 'return nil, errtxt', which follows the pattern of many Lua functions, such as 'io.open()'. The user can then choose to handle the situation in a manner appropriate for his code. To maintain the previous behavior, the user may call 'assert(posix.parse(...))'.
-rw-r--r--posixtz.lua13
1 files changed, 6 insertions, 7 deletions
diff --git a/posixtz.lua b/posixtz.lua
index ae84275..eb1e56e 100644
--- a/posixtz.lua
+++ b/posixtz.lua
@@ -13,7 +13,6 @@
-- Import Section
-- declare everything this module needs from outside
-local error = error
local tonumber = tonumber
local pairs = pairs
local ipairs = ipairs
@@ -33,7 +32,7 @@ function parse ( str )
local temp = {}
if not str then
- error('Nothing to parse')
+ return nil, 'Nothing to parse'
end
@@ -50,7 +49,7 @@ function parse ( str )
-- tz.std must be defined by now
if not tz.std then
- error('Not a valid POSIX TZ. "std" invalid')
+ return nil, 'Not a valid POSIX TZ. "std" invalid'
end
@@ -73,7 +72,7 @@ function parse ( str )
end
else
- error('Not a valid POSIX TZ. "offset" invalid')
+ return nil, 'Not a valid POSIX TZ. "offset" invalid'
end
@@ -95,14 +94,14 @@ function parse ( str )
tz.dst.name, temp.afterdst = string.match(temp.afteroffset, '^(%a+)(.*)')
end
if not tz.dst.name then
- error('Not a valid POSIX TZ. "dst" present but not valid')
+ return nil, 'Not a valid POSIX TZ. "dst" present but not valid'
end
-- tz.dst.name is defined, so process "rule"
-- Parse out specifications from "rule"
temp.dststart, temp.dststop = string.match(temp.afterdst, '^,([^,]+),([^,]+)')
if not temp.dststart then
- error('Not a valid POSIX TZ. "dst" present but "rule" is not')
+ return nil, 'Not a valid POSIX TZ. "dst" present but "rule" is not'
end
@@ -178,7 +177,7 @@ function parse ( str )
-- Validation: t.month must be defined by now.
if not t.month then
- error('Not a valid POSIX TZ. "rule" for DST "'..pos..'" is invalid')
+ return nil, 'Not a valid POSIX TZ. "rule" for DST "'..pos..'" is invalid'
end
end