Jump to content




Display Error in another Program


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

#1 Chickenbreadlp

  • Members
  • 73 posts
  • LocationGermany

Posted 01 May 2014 - 04:02 PM

I'm working on an OS and i want to Display Errors that were caused by a program in another Program. How do i dow this?
My Example:

Program 1 Is crashed because an 'end' was missing. In a shell The following error would be displayed:

bios:366: [string "PROGRAMNAME"]:LINE: 'end' expected (to close 'CAUSE' at line LINE)

Bluescreen is automaticly displayd which should shows:

ERROR!!! Crash Code:
LINE: 'end' expectet (to close 'CAUSE' at line LINE)

(or something like that)

Can i do this somehow?

Edited by Chickenbreadlp, 01 May 2014 - 04:04 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 May 2014 - 04:08 PM

pcall() sounds like what you're after.

#3 Chickenbreadlp

  • Members
  • 73 posts
  • LocationGermany

Posted 01 May 2014 - 05:47 PM

Either i'm too dumb to use it or I'm using pcall() wrong... my OS uses multiple programs. I'm tested the following code in my Program:
local status = pcall(function () shell.run("ApfelOS/aLogin.adf") end)
print(status)
(please note, that this is exactly the same code that i tested)
but if an error appears or not, it says every time true

Edited by Chickenbreadlp, 01 May 2014 - 05:47 PM.


#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 01 May 2014 - 06:01 PM

That's because os.run is already pcall-ing the program. If it errors, it prints the error and exits cleanly. You'll need to write a modified version of os.run and use it instead of calling shell.run.

#5 Chickenbreadlp

  • Members
  • 73 posts
  • LocationGermany

Posted 01 May 2014 - 06:11 PM

I'm a little bit dumb about that. How do i do this? (normally i only need an example)

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 02 May 2014 - 01:13 AM

The source is found in bios.lua:

function os.run( _tEnv, _sPath, ... )
    local tArgs = { ... }
    local fnFile, err = loadfile( _sPath )
    if fnFile then
        local tEnv = _tEnv
        --setmetatable( tEnv, { __index = function(t,k) return _G[k] end } )
        setmetatable( tEnv, { __index = _G } )
        setfenv( fnFile, tEnv )
        local ok, err = pcall( function()
            fnFile( unpack( tArgs ) )
        end )
        if not ok then
            if err and err ~= "" then
                printError( err )
            end
            return false
        end
        return true
    end
    if err and err ~= "" then
        printError( err )
    end
    return false
end


#7 Chickenbreadlp

  • Members
  • 73 posts
  • LocationGermany

Posted 02 May 2014 - 10:32 AM

I think, i'm too dumb for that, because now it either says:
window:57:expectet Number
Press any key
or it says:
bios:attempt to call nil
(i have forgotten the number at the second one)
I need to run a program which has some color variables in it to have something like a theme.

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 02 May 2014 - 03:53 PM

Sorry, can't really comment on that without seeing the script(s) that led to those errors.

#9 apemanzilla

  • Members
  • 1,421 posts

Posted 02 May 2014 - 04:56 PM

Try this.
local status, error = pcall(function() dofile("filename") end)


#10 Chickenbreadlp

  • Members
  • 73 posts
  • LocationGermany

Posted 02 May 2014 - 08:05 PM

Now my code is ready to publish, because i must check if there is anything that i don't want to show so here it is:
1st Program:
Spoiler
2nd Program:
Spoiler
3rd program:
Spoiler
please note, that there are the original path's in this code. you have to change them to get it work

#11 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 03 May 2014 - 01:56 PM

View Postapemanzilla, on 02 May 2014 - 04:56 PM, said:

Try this.
local status, error = pcall(function() dofile("filename") end)
Why dont you use the proper way of calling pcall, it has more arguments than one. Anonymous functions should only be used if you want to execute a chunk of code rather than just one function call. The proper of calling pcall in this matter is:
local status, err = pcall( dofile, "filename" )
And don't overwrite the global error function in your code, it can lead to unexpected errors :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users