Posted 14 November 2015 - 02:43 AM
Lets say I use the following code:
When I run this code, it will return an error: "string:2: hey". This makes debugging stupidly hard as the file is not specified. I would like to know if there a way to catch this error and append custom information to the front of it so I know what file this error originated from.
Because I have around 50 files being loaded through this method, I need the solution to be a runtime solution because the file won't be used immediately after loading. Other data will be loaded using this method before it maybe used.
Perhaps some sort of coroutine or wrapping of the function that will catch any errors that occur during runtime.
- Thanks, Harry.
local ok, err = loadstring([[
_G.test = function()
error("hey")
end
]])
if not ok and err then
print( err )
end
local ok, err = pcall( ok )
if not ok and err then print(err) end
test()
When I run this code, it will return an error: "string:2: hey". This makes debugging stupidly hard as the file is not specified. I would like to know if there a way to catch this error and append custom information to the front of it so I know what file this error originated from.
Because I have around 50 files being loaded through this method, I need the solution to be a runtime solution because the file won't be used immediately after loading. Other data will be loaded using this method before it maybe used.
Perhaps some sort of coroutine or wrapping of the function that will catch any errors that occur during runtime.
- Thanks, Harry.
Edited on 14 November 2015 - 02:00 AM