Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 25, 2019 1:26 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Error Handling
PostPosted: Sun Dec 04, 2011 1:01 pm 
Offline

Joined: Sun Dec 04, 2011 11:40 am
Posts: 7
Hello people, I am new in Real programming,
and I have some problems to handle error.

In Visual Basic 6 to ignore error i write in a rotine:
on error resume next,

1) what is the correspondent command in Real Basic?

And in VB I write:
Private Sub Cercaqualcosa()
dim c as double
On error goto pippo
c = 1/0
exit sub
pippo:
MsgBox("err",vbMsgYesNo, "evento errore")
end sub

2) In RB what is the correspondant syntax of this?

Thank you. Marco


Top
 Profile  
Reply with quote  
 Post subject: Re: Error Handling
PostPosted: Sun Dec 04, 2011 2:46 pm 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
On error resume next was always 'bad' but easy to do.

On error resume next
c = 1/0
d = 20 * c 'what should this be??

So nothing happened when the divide by zero occurred. Sometimes good, sometimes you don't know how bad your code is.

In RB, there are several ways to handle errors.

If there is a chance of a zero division, you can do this:


try
c=1/0
catch
msgbox "There was a divide by zero error, if you are interested"
c = 0 ' this is how I take care of the problem
end try
d = 20 * c 'perfectly safe and handled even if there was a problem



You can nest try ..catch statements.


If you prefer to work more like RB, you don't use try..catch
Instead, put the word exception at the end of the method
Code under that occurs when an error happens.
You can set a message box, log an error, quit the method, or (shudder) use a goto to continue in another place.


c = 1/0

d = 10 'this does not get executed

exception
mgsbox "an error occurred" 'etc

end sub


Top
 Profile  
Reply with quote  
 Post subject: Re: Error Handling
PostPosted: Sun Dec 04, 2011 3:31 pm 
Offline

Joined: Sun Dec 04, 2011 11:40 am
Posts: 7
Ok, Kermit,
but if I use Eception,
how can I continue execution of application?
Because after Show me the text box
the program shut down...

Here my problem:

Dim f as FolderItem
Dim p as Picture
Dim maxW, maxH as Integer

maxW = Canvas.width
maxH = Canvas.height

try '(is no here the problem)
f = GetFolderItem(percorso.text) 'percorso as a text box where I put my file path
if f <> Nil Then
p=f.OpenAsPicture
end if
end try

factor = min (maxW / p.Width, maxH / p.Height)
factor = min( factor, 1.0)
pic = NewPicture (p.Width * factor, p.Height * factor , 32)
pic.graphics.DrawPicture p, 0,0,pic.width,pic.height, 0,0,p.width,p.height
Canvas.Backdrop = pic

Exception
Canvas.Backdrop = nil 'where path no exist crash program


Top
 Profile  
Reply with quote  
 Post subject: Re: Error Handling
PostPosted: Sun Dec 04, 2011 4:11 pm 
Offline

Joined: Sun Dec 04, 2011 11:40 am
Posts: 7
I find my problem!!!
No shut down application!
Is just debugger to show stop for error but pushing continue it continue.

Thank. Bye


Top
 Profile  
Reply with quote  
 Post subject: Re: Error Handling
PostPosted: Mon Dec 05, 2011 2:17 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
try '(is no here the problem)
f = GetFolderItem(percorso.text) 'percorso as a text box where I put my file path
if f <> Nil Then
p=f.OpenAsPicture
end if
catch
end try


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group