Snippets

Richard Yu VCMP Client Error Handling

Created by Richard Yu last modified
// https://github.com/albertodemichelis/squirrel/blob/master/sqstdlib/sqstdaux.cpp https://bitbucket.org/stormeus/vl8-pb400/src/master/LibErrors.nut
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);

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.