Author Topic: Event OnScriptError  (Read 1496 times)

sasha19323

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +25/-24
    • View Profile
Event OnScriptError
« on: October 15, 2013, 05:45:58 pm »
Is it possible to call any function if script get error?

Sorry for poor english

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Event OnScriptError
« Reply #1 on: October 16, 2013, 01: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.

Shadow.

  • Tester
  • Full Member
  • ****
  • Posts: 144
  • Karma: +16/-35
    • View Profile
Re: Event OnScriptError
« Reply #2 on: October 16, 2013, 03: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.

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Event OnScriptError
« Reply #3 on: October 16, 2013, 07: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 );

}

sasha19323

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +25/-24
    • View Profile
Re: Event OnScriptError
« Reply #4 on: October 16, 2013, 10:29:17 pm »
Thx to all, guys  :)

 

© Liberty Unleashed Team.