Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Error handling


Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2007, 07:28 AM
ellebanna's Avatar
ellebanna ellebanna is offline
Centurion
 
Join Date: Apr 2003
Location: US, Pennsylvania
Posts: 137
Lightbulb Error handling


If i have this procedure for example:

Sub Main()
On error goto x
code -------
code--------
subroutine()
exit sub
x:
--log error here
End sub

Sub subroutine()
On error goto y
code
exit sub
y:
log error
err.clear
Exit sub

Question: If i clear the error in the subroutine, will it still kill the whole process or will it think that there is no longer an error when it goes back to main() ?
Reply With Quote
  #2  
Old 09-28-2007, 07:45 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

If the error is handled you will not get into a higher level error handler, no matter whether you cleared the err object or not.
Reply With Quote
  #3  
Old 09-28-2007, 08:13 AM
ellebanna's Avatar
ellebanna ellebanna is offline
Centurion
 
Join Date: Apr 2003
Location: US, Pennsylvania
Posts: 137
Default

Thanks.
So what is the best way to handle the error so i can log where the error has occured in a more specific breakdown. I guess what I'm asking is if the error occured in the subroutine, i would like to log the error that it occured in the subroutine, not in main.
__________________
It's never easy when you dont know the answer....
Reply With Quote
  #4  
Old 09-28-2007, 09:19 AM
jaxbot jaxbot is offline
Regular
 
Join Date: Sep 2007
Posts: 54
Default

Normally, if you use the "On error" commands, it will ignore the error, so long as it's not critical (eg missing DLL file).
Reply With Quote
  #5  
Old 09-28-2007, 12:05 PM
Stalemate Stalemate is offline
Contributor

* Expert *
 
Join Date: Mar 2004
Posts: 614
Default

The error is not ignored, it's directed to the specified handler.
Now your handler can do what it wants with the error. Log it, notify the user, try fixing the problem itself.
Errors should not be ignored...

To recieve information about errors in a subroutine you can use a return value from the function to determine success or error specification.
Note that an 'On Error' statement is effective for subroutines called from the main procedure containing the statement.
Example: (run the following and see what happens)
Code:
Sub Main() On Error GoTo errH Debug.Print SubSub Exit Sub errH: Debug.Print Err.Number, Err.Description End Sub Function SubSub() As Boolean Debug.Print 1 / 0 SubSub = True End Function
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->