Jump to content




editing the error function


  • You cannot reply to this topic
8 replies to this topic

#1 Exerro

  • Members
  • 801 posts

Posted 06 January 2013 - 06:10 AM

i am making a thingy like love2d but for computercraft but i want to have custom error catching...where you can disable the code stopping if a certain variable is true i.e. sky.finalRelease = true but im not sure how to 1) make a function that can terminate all running programs and quit and then display the error and 2) find the error function to copy&edit
Can someone either tell me where the error() code is or a way to stop all running programs and display what went wrong (just like the error() function)

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 January 2013 - 08:22 AM

http://www.computerc...dpost__p__66717

#3 Exerro

  • Members
  • 801 posts

Posted 06 January 2013 - 09:13 AM

that would mean you had to do it with every function though? im making something like love2d so its basically just a bigger library with a couple of multitasking features and organisation features build in so making the user have to type that in every time would be pointless
Thanks though im sure it will help me with some other things
Does it check for errors through the whole code and even check functions in functions? i.e.
function f1()
    f2()
end
function f2()
    error here
end
ok, error = pcall(f1)
if not ok then
    print(error)
end


#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 January 2013 - 09:17 AM

I'm actually making a library similar to yours, except it's more of a literal remaking of love, haha.

But here's how I do things - I just wrap the operation of the user-defined functions in a pcall, instead of pcalling every single function.

local function run(fps)
  -- stuff that runs all of the functions
end

function start(fps)
  local ok, err = pcall(run, fps)
  -- have a function pcalling the running functions
end


#5 Exerro

  • Members
  • 801 posts

Posted 06 January 2013 - 09:20 AM

a) omg we should work together...my library addons are epic and it sound like ur organisation and multitasking(love.update,love.draw stuff ) etc are epic too
B)<--- stupid smileys(this is a b )) does pcall run the function or does it just check for errors
c) in java there is try and catch...is it possible to make a lua clone of this?

randomly spreading my code to everyone :P :
Spoiler


#6 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 January 2013 - 09:27 AM

pcall runs the function as well as catching the errors. And honestly, pcall is basically the same thing as try/catch, so there wouldn't be much of a point. I'm interested if anyone else can implement sort of a makeshift try/catch, though.

#7 Exerro

  • Members
  • 801 posts

Posted 06 January 2013 - 09:28 AM

read a) and B)
edit: just a)
edit 2: so if there is an error...instead of error()ing it the pcall will stop the function and return what the error was?

#8 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 January 2013 - 09:35 AM

View Postawsumben13, on 06 January 2013 - 09:28 AM, said:

edit 2: so if there is an error...instead of error()ing it the pcall will stop the function and return what the error was?
Yep.

But eh, I usually work alone on things like this.

#9 Exerro

  • Members
  • 801 posts

Posted 06 January 2013 - 09:38 AM

:l k...is there any way to not let the program stop if there is an error? i.e. a critical error so term.setCursorPos(1) would just do nothing instead of error()ing or pcall()ing





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users