Liberty Unleashed

Scripting => Script Help => Topic started by: sasha19323 on October 15, 2013, 04:45:58 pm

Title: Event OnScriptError
Post 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
Title: Re: Event OnScriptError
Post by: Vortrex on October 16, 2013, 12:04:03 am
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:
Code: [Select]
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.
Title: Re: Event OnScriptError
Post by: Shadow. on October 16, 2013, 02:53:52 pm
you can have this:

Code: [Select]
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.
Title: Re: Event OnScriptError
Post by: Thijn on October 16, 2013, 06:55:16 pm
This will display about the same info the error message in your console gives.

All credits go to Stormeus for this code.
Code: [Select]
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 );

}
Title: Re: Event OnScriptError
Post by: sasha19323 on October 16, 2013, 09:29:17 pm
Thx to all, guys  :)