Vice City: Multiplayer

Server Development => Scripting and Server Management => Client Scripting => Topic started by: ysc3839 on May 01, 2016, 06:50 AM

Title: [SNIPPET] Error Handling
Post by: ysc3839 on May 01, 2016, 06:50 AM
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)
Title: Re: [SNIPPET] Error Handling
Post by: DizzasTeR on May 01, 2016, 08:56 AM
Ah that's better, now no need to go at debugfile the whole freaking time, thanks!
Title: Re: [SNIPPET] Error Handling
Post by: kingofpopYT on May 03, 2016, 09:37 AM
where do we have to add?
Title: Re: [SNIPPET] Error Handling
Post by: ysc3839 on May 03, 2016, 09:48 AM
Quote from: coalman on May 03, 2016, 09:37 AMwhere do we have to add?
On the top of your script. Or use dofile.
Title: Re: [SNIPPET] Error Handling
Post by: Luis_Labarca on Jul 24, 2016, 07:35 PM
hey bro I have a problem I add Console.Print ("test") or Print ("test"); in Script::ScriptLoad() and I get nothing on console
Title: Re: [SNIPPET] Error Handling
Post by: Thijn on Jul 24, 2016, 08:39 PM
It should be in your log file, not in your console.
Title: Re: [SNIPPET] Error Handling
Post by: Luis_Labarca on Jul 25, 2016, 03:24 AM
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 ;)