Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling ¦ Pictures Question

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
Number One:
Whats the best way to do error handling, I currently use on error goto.

Number Two,
Why doesn't my save picture work, it says expect function. Brad,
Free mp3 player,games and more.
 
First One Only.

That is the best way. In your error handler you can further say (if you're manipulating a DB)

if myDB.Errors.Count>0 then
select case myDB.Errors(0).NativeError
case CONST_DUPLICATE 'Is the Error Number according to
'whichever database you are using
msgbox "The Record Already Exists",vbExclamation
case CONST_PARENT_NOT_FOUND
....
case CONST_CHILD_RECORD_FOUND
....
case else
Msgbox Err.Description
end select
else
Msgbox Err.Description
end if
 
Who said anything about databases?

On error goto is a good way to deal with errors (I'm not the one to say the it is THE best way). This is how error handling could look like:
--------------------------------------------------
sub MySub
on error goto ErrHndl.

'code here
'you can use Err.raise to generate errors.

end

ErrHndl:
if Err.number=MyErrNumber then
'deal with error
resume next
elseif Err.number=MyOtherErrNumber then
'deal with error
resume 0
else
msgbox Err.description
end if

end sub
----------------------------------------------------

Please post your savepicture code...

SunajWho said anything about databases?

On error goto is a good way to deal with errors (I'm not the one to say the it is THE best way). This is how error handling could look like:
--------------------------------------------------
sub MySub
on error goto ErrHndl.

'code here
'you can use Err.raise to generate errors.

end

ErrHndl:
if Err.number=MyErrNumber then
'deal with error
resume next
elseif Err.number=MyOtherErrNumber then
'deal with error
resume 0
else
msgbox Err.description
end if

end sub
----------------------------------------------------

Please post your savepicture code...

Sunaj
 
This is what I am using currently.
retval = Picture(Picture1, "C:\test.bmp")

Now picture one does not have any actual picture but i contains images which have pictres. Brad,
Free mp3 player,games and more.
 

Hmm I haven't seen that before, the standard way to save an image as a bitmap is

SavePicture Picture1.Image, "C:\test.bmp"

Sunaj
 
OK, I'm going to get horribly beaten for this one, but perhaps this thread could finally make me change my error handling ways ... :)

I'm not a big fan of blanket error handling code - I think that it makes errors very difficult to find in testing.

The way that I do error handling is like this.

1) Option Explicit in every file - probably the most important thing.

2) Check every return value from every function, and do something sane

3) Use On Error Resume Next and If Err around portions of code that can raise errors. Handle the errors at the point they occur, if possible.

4) If the error is disastrous, bring up a dialog box telling the user and exit immediately. Do NOT try to save state, as you have no idea what the state is.

This is just a basic framework of my error handling. OK guys, open season. Shoot me down.

Chaz
 

Hi Chaz,

I won't shoot on anybody and actually think that the method you describe is very similar to mine. The differences as I see it are:
1) The error handling code is in you case located 'inline' and in my at the end of the sub. That not really a big differece but a matter of taste.
2) An error occuring outside one of your 'If Err' might cause trouble for the program, whereas with 'goto errhndl' you'll be able to do something about the unknown problem (reset variables and start agian, let the user select whats to happen etc.)

on error goto ErrHndl can be the biggest pain in the ... when you are debugging, but I think is nice to have you error handling code in one place and usually comment out the 'on error goto' when debugging.

I'm a big fan of option explicit. I alsway use it, but again ist really mostly for debugging purposes.


Sunaj
 
This is where all of my 'discussions' about error handling end - what about unhandled errors?

This is what testing is about. Testing finds spots in your code where you have forgotton to put error handling code.

OK, there are going to be situations where the application just crashes through no fault of your own - out of memory, for example. I think that this is acceptable, given the increased reliability of the application in normal use. Putting in a global error handler to catch this is a trap, allowing lots of little bugs to survive.

Chaz
 
Thanks for your help,
I still need help though. The save picture works. But the the picturebox CONTAINS images they are "inside" the picture box. The image does not contain them =-(. I tried picture.container in the save statement but its to of no use.

Any ideas?
Brad,
Free mp3 player,games and more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top