Liberty Unleashed
Scripting => Script Help => Topic started by: sasha19323 on October 15, 2013, 04:45:58 pm
-
Is it possible to call any function if script get error?
Sorry for poor english
-
Shadow and I discussed this once. He knows more about it than I do, so he'd be the person to properly answer this question.
However, in my attempt to assist you, I think the function you are looking for is:
seterrorhandler( );Or something to that effect.
EDIT: I forgot to add that there is one parameter to this function, which is the function that needs to be called on an error.
-
you can have this:
function onScriptLoad() {
seterrorhandler( errHandler );
}
function errHandler( errorobject )
{
print( "Error: " + errorobject );
}
you can also use getstackinfos(2) to retrieve the line/function/source the error happens at, it's quite useful.
thanks to Stormeus for pointing this out long time ago.
-
This will display about the same info the error message in your console gives.
All credits go to Stormeus for this code.
seterrorhandler( errorHandling );
function errorHandling( obj )
{
// Get the stack info we need to log
local callingStack = getstackinfos( 2 );
// And record them to their own variables
local funcName = callingStack.func;
local origin = callingStack.src;
local lineNo = callingStack.line;
local locals = "";
// Get all the locals we can
foreach( index, value in callingStack.locals )
{
if( index != "this" )
locals = locals + "\t[" + index + "]: " + value + "\n";
}
print( "Error occurring in " + origin + ":" + lineNo + ", function " + funcName + "." );
print( ">> " + obj + "\n" );
print( locals );
}
-
Thx to all, guys :)