Handles the error and print to console. You also can print to your own console.
function errorHandling(err)
{
local stackInfos = getstackinfos(2);
if (stackInfos)
{
local locals = "";
foreach( index, value in stackInfos.locals )
{
if( index != "this" )
locals = locals + "[" + index + "] " + value + "\n";
}
local callStacks = "";
local level = 2;
do {
callStacks += "*FUNCTION [" + stackInfos.func + "()] " + stackInfos.src + " line [" + stackInfos.line + "]\n";
level++;
} while ((stackInfos = getstackinfos(level)));
local errorMsg = "AN ERROR HAS OCCURRED [" + err + "]\n";
errorMsg += "\nCALLSTACK\n";
errorMsg += callStacks;
errorMsg += "\nLOCALS\n";
errorMsg += locals;
Console.Print(errorMsg);
}
}
seterrorhandler(errorHandling);
Code also can be found here: https://bitbucket.org/snippets/ysc3839/p64jG
Test code:
function Script::ScriptLoad()
{
local t = null;
Console.Print(t.t);
}
Output:
AN ERROR HAS OCCURRED [the index 't' does not exist]
CALLSTACK
*FUNCTION [ScriptLoad()] Main Script line [37]
LOCALS
[this] (class : 0x0EEA1820)
[t] (null : 0x00000000)
Ah that's better, now no need to go at debugfile the whole freaking time, thanks!
where do we have to add?
Quote from: coalman on May 03, 2016, 09:37 AMwhere do we have to add?
On the top of your script. Or use dofile.
hey bro I have a problem I add Console.Print ("test") or Print ("test"); in Script::ScriptLoad() and I get nothing on console
It should be in your log file, not in your console.
Quote from: Thijn on Jul 24, 2016, 08:39 PMIt should be in your log file, not in your console.
Ah do not know that bro I set thanks ;)