I developed an application in VB6. In client's environment it raises runtime errors which I can't reproduce under debugger. Is there any way to get the stacktrace or location of error?I created log file and
I used Err.Description,Err.Source but it gives blank values.
C# developers get a feature that Visual Basic Developers have had since.NET Framework 3.0. News; In-Depth. What's New in C# 6.0: Selecting Exceptions in a Try.Catch Block. Visual Studio Live! Boston June 9-13, 2019 Boston, MA Training Seminar: San Jose.
Please help me.
Royson
RoysonRoyson1,1661111 gold badges2525 silver badges4949 bronze badges
4 Answers
You've probably done something to clear the
T.J. CrowderT.J. CrowderErr
object before writing to the log file. This is very, very easy to do. What you'll want to do is as soon as you detect an error has occurred, grab the error message before doing anything else. Then pass the error message to whatever logging routine you're using. E.g.:717k131131 gold badges12971297 silver badges13731373 bronze badges
BTW, thanks for your guys' answers helping me. I'm about half a decade late to the game of VB6. I don't do windows unless forced to. ;)
Anyhow, when doing your error checking, say among 3000 individual record query insertions, I learned a couple tricks. Consider this block of code:
When not testing for Err.Number, you'll get a 0: on every order handled. (maybe you don't want that). The On Error GoTo -1 resets the error so that it will work again. Apparently, Err only works 'once'.
I wrote a php script to build the VB6 source code to run some 8000 odbc queries... :P
Chris KChris K16.1k22 gold badges2626 silver badges4141 bronze badges
Do you definitely, positively have an
MarkJExit Function
just above the Error_Handler:
?MarkJ
27.7k44 gold badges5555 silver badges9696 bronze badges
'Exit Sub' should be added before you handle the Error_Handler function.....
Sandeep PuvvadiSandeep Puvvadi
Not the answer you're looking for? Browse other questions tagged vb6error-handling or ask your own question.
I am working on an employee database and am having issues with my TRYCATCH for saving records as it pertains to exception handling. The issue I am experiencing is that it will run the TRY and ignore the CATCH, allowing invalid data to pass and save to the file. I am very new to visual basic and am unsure of why this is not working. Here is my code for the form:
djv8,60677 gold badges3434 silver badges5454 bronze badges
user7217915user7217915
1 Answer
A
Catch
block only executes if an exception is thrown from within the Try
block. I don't see anything here which would cause that to happen. It appears as though you're misunderstanding this a bit.Don't put validation logic in a
Catch
block. All that should go there is code to handle an exception if one occurs. For example, if the connection to a database fails because the database itself is offline, or if writing to a file fails because the file can't be found/opened.Put your validation logic before you even make the attempt to save it. If the user input fails validation, don't attempt to save it. Instead, return an error to the user. Only if your custom validation passes would you then begin the
DavidDavidTry
, write to your data store, and handle an exception if one occurs.153k2929 gold badges153153 silver badges218218 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.