destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
03:37 PM
BreakIfRunError
I was looking for a way to include user-defined error handling in a script for Roku. I see this -
This doesn't work if your script you run tries to make use of an invalid component method - such as screen.getmyvalue()
It crashes back to the debugger without proceeding with execution to print the runtime error.
Is there a way to check and handle invalid methods for components?
Sub Main()
Run("pkg:/test.brs")
BreakIfRunError(LINE_NUM)
Print Run("test2.brs", "arg 1", "arg 2")
if Run(["pkg:/file1.brs","pkg:/file2.brs"])<>4 then stop
BreakIfRunError(LINE_NUM)
stop
End Sub
Sub BreakIfRunError(ln)
el=GetLastRunCompileError()
if el=invalid then
el=GetLastRunRuntimeError()
if el=&hFC or el=&hE2 then return
'FC==ERR_NORMAL_END, E2=ERR_VALUE_RETURN
print "Runtime Error (line ";ln;"): ";el
stop
else
print "compile error (line ";ln;")"
for each e in el
for each i in e
print i;": ";e[i]
end for
end for
stop
end if
End Sub
This doesn't work if your script you run tries to make use of an invalid component method - such as screen.getmyvalue()
It crashes back to the debugger without proceeding with execution to print the runtime error.
Is there a way to check and handle invalid methods for components?
9 REPLIES 9
YungBlood
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
04:41 PM
Re: BreakIfRunError
Can you post the test script that is crashing? I use that kind of code to keep Games 4 Roku from crashing when I'm testing games, and it works fine for me.
YungBlood
Bringing more fun to Roku!
Bringing more fun to Roku!
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
05:28 PM
Re: BreakIfRunError
I have it load "pkg:/source/test.brs"
test.brs has
Function Main()
Return CreateObject("roDeviceInfo").GetCountryCode()
End Function
It crashes with member function not found in brightscript interface rather than returning the runtime error code to the original app.
I know it's not valid - I just want it to properly handle the error and set variables based on failure.
And yes, removing the stop in the calling routine and adding code to it doesn't execute. So it doesn't appear to handle this properly. 😞
test.brs has
Function Main()
Return CreateObject("roDeviceInfo").GetCountryCode()
End Function
It crashes with member function not found in brightscript interface rather than returning the runtime error code to the original app.
I know it's not valid - I just want it to properly handle the error and set variables based on failure.
And yes, removing the stop in the calling routine and adding code to it doesn't execute. So it doesn't appear to handle this properly. 😞
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
06:20 PM
Re: BreakIfRunError
changing the loaded script to alternates doesn't produce different results either - like
Function Main()
m.country=CreateObject("roDeviceInfo").GetCountryCode()
End Function
Basically I thought the whole load a script and return/print errors would work like "on error resume next" for vbscript, or an exception handler try block in C++, but no matter what, in brightscript, a crash crashes in this instance.
Any other solutions?
I suppose I could get around it by not using the command that fails, but sending a request to the server and have the server determine which country the request is coming from based on the external request IP, but that is more work than having the app try to determine it, and then set to USA if it fails.
http://www.go4expert.com/forums/showthread.php?t=3511
Function Main()
m.country=CreateObject("roDeviceInfo").GetCountryCode()
End Function
Basically I thought the whole load a script and return/print errors would work like "on error resume next" for vbscript, or an exception handler try block in C++, but no matter what, in brightscript, a crash crashes in this instance.
Any other solutions?
I suppose I could get around it by not using the command that fails, but sending a request to the server and have the server determine which country the request is coming from based on the external request IP, but that is more work than having the app try to determine it, and then set to USA if it fails.
http://www.go4expert.com/forums/showthread.php?t=3511

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
06:25 PM
Re: BreakIfRunError
Have you tried an Eval() on the line of code you want to execute instead of trying to run a full script?
Side note, is GetCountryCode() supposed to work? I'm not sure I understand what you're trying accomplish, unless that's a method that's not documented somewhere...?
Side note, is GetCountryCode() supposed to work? I'm not sure I understand what you're trying accomplish, unless that's a method that's not documented somewhere...?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
06:39 PM
Re: BreakIfRunError
Eval fails too as it doesn't exist in the current firmware.
I'm trying to find a way to not have to rely on the version number reported by the device before trying to execute new code elements provided in future firmware.
The method is supposed to report the region the roku device is in, so you can contact the closest CDN to the user. - so it would return "US" or "UK" or other or something for the country code.
I'm trying to find a way to not have to rely on the version number reported by the device before trying to execute new code elements provided in future firmware.
The method is supposed to report the region the roku device is in, so you can contact the closest CDN to the user. - so it would return "US" or "UK" or other or something for the country code.

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
06:51 PM
Re: BreakIfRunError
"destruk" wrote:
Eval fails too as it doesn't exist in the current firmware.
I'm trying to find a way to not have to rely on the version number reported by the device before trying to execute new code elements provided in future firmware.
The method is supposed to report the region the roku device is in, so you can contact the closest CDN to the user. - so it would return "US" or "UK" or other or something for the country code.
The following works for me...
' Initialize the country variable
country = invalid
' Create a device info object
deviceInfo = CreateObject("roDeviceInfo")
' Attempt to use GetCountryCode() to set country
' Eval returns the error code, so the print should print it to the console (252 = success)
print Eval("country = deviceInfo.GetCountryCode()")
' If the eval failed, set the country to US
If country = invalid Then
country = "US"
End If
print country
Where did you read about GetCountryCode, if I may ask? I have a need for that, but don't see it documented anywhere...
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
07:36 PM
Re: BreakIfRunError
Thanks for that TheEndless - we're trying to port a channel to the european channel store and RokuPatrick told us to use GetCountryCode to host the same app in all channel stores.
The method still fails (error code 244) - but with your code it proceeds as desired so I'll say it's resolved until I can test it again with a working method in a future firmware revision.
My eval wasn't working as I didn't use quotes.
The method still fails (error code 244) - but with your code it proceeds as desired so I'll say it's resolved until I can test it again with a working method in a future firmware revision.
My eval wasn't working as I didn't use quotes.
Function GetCountryCode()
result=invalid
' Create a device info object
deviceInfo=CreateObject("roDeviceInfo")
' Attempt to use GetCountryCode() to set country
' Eval returns the error code, so the print should print it to the console (252 = success)
result=Eval("country=deviceInfo.GetCountryCode()")
if result<>252
Return "US"
else
Return deviceInfo.GetCountryCode()
end if
'returns country code
'US
'CA (Canada)
'GB (UK)
'IE (Ireland)
'OT (Other)
End Function

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
07:51 PM
Re: BreakIfRunError
Nice. Thanks for the extra info.
As for your code, you may already realize it, but you're duplicating a call. The Eval runs in the context of the current script, so it's setting the value of "country" (assuming a successful result) which is accessible to the rest of your code, so you're second call to GetCountryCode isn't really necessary.
As for your code, you may already realize it, but you're duplicating a call. The Eval runs in the context of the current script, so it's setting the value of "country" (assuming a successful result) which is accessible to the rest of your code, so you're second call to GetCountryCode isn't really necessary.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012
08:06 PM
Re: BreakIfRunError
Thankyou for the help.
That should be better.
Function GetCountryCode()
result=invalid
country=invalid
' Create a device info object
deviceInfo=CreateObject("roDeviceInfo")
' Attempt to use GetCountryCode() to set country
' Eval returns the error code, so the store the return code in result (252 = success)
result=Eval("country=deviceInfo.GetCountryCode()")
if result<>252
Return "US"
else
Return country
end if
'returns country code
'US
'CA (Canada)
'GB (UK)
'IE (Ireland)
'OT (Other)
End Function
That should be better.