I have a Try...Catch statement that contains 12 Operations inside it. On the catch I want to display a msgbox that tells exactly which operations failed. I was looking through the exception methods and couldn't find one that worked. All of the methods provided relative information but nothing specific.
The reason I want to pinpoint exactly which operations failed is so that the user can email the error message to me and when I get it I will know exactly how to fix it.
Thanks.

Try...Catch statement Question
Artyom
Blair Hall
You'll have to keep track of that yourself.
Rajaraman Soundararajan
selotz
That's the reason they are all in one try statement. They all pretty much do the same thing.
JoseMiguel
you use a function, you say
Excellent
The solution is to throw your own exceptions. In the function that sets the value of the trackbar to equal the text in the textbox verify the number. Use Double.TryParse() (Or Integer.TryParse if you're confident about the range) in your function. If TryParse returns false the text could not be converted to a number. Throw your own exception and include information about which textbox failed. ApplicationException might work for this but you might be better of extending it in your own class.
There are times where you want to catch exceptions and times where you want them to bubble up. There are also times where you want to want to let called code throw its own exceptions and times where you can predict them and you'd rather throw them yourself.
nokushi0
No, you can't. Blairs code will give you what is possible, which is no more granular than the scope of your try/catch statement.
If I need to do something like this, I create a progress string, and set it to tell me where within an operation I am. Then I write that string to my log in an error. I only do this when I know there is a problem within a specific block on a client machine that I cannot replicate.
Charlie Babbage
So, when I set the text of all the textboxes at once, it calls my function to set the trackbar to the same value, and if it fails then the exception is thrown. But, since there are many textboxes and more than one of them can fail, it would be nice to know which one failed.
I think I will probably use a seperate try statement for each textbox, unless anybody con figure out a different way.
trident
For example my breakpoint details say: At Form1.vb, line 129 character 13 ('Char1_Read', line 25)
I want details like that.
LuckyStarfo
This is what I want my statement to do: show a msgbox when an exception is thrown and set a variable if an exception is not thrown but only if an exception is not thrown. How would I do this
lvandiest
Hey Troy. . . Lets go an entirely different direction!!!
Lets let the wonderful Windows.Forms namespace work for us!!!
play along with me -
create a VB windows application
drop three text boxes on Form1 - TextBox1, TextBox2. TextBox3
drop an Error Provider on Form1 - ErrorProvider1
drop two buttons on Form1
The error provider is a control extender that adds properties to all the controls. The important one is Error on ErrorProvider1
put this code in the Form1.vb
Compile and run
In short. . . set the text in the text boxes. .. then validate the text boxes. .. if validation fails, let the error provider give a visual queue as to what data is not valid. Tooltip on the control now displays the error. No clunky exception handling, either.
Now, here is the beauty - The form only functions as a presentation, it does no data analysis (well yes, we load the data, and we validate the data here but only for simplicity, in theory that functionality could be "delegated")
macupryk
If I gather correctly you are trying to assertain the offending portion of the input file. If that's the case I would advise including the FileStream position in the error report. If you're sending the report from the application you might also include the whole file. If that's not an option, in the catch block record the current position in the filestream. Close it, reopen it, capture about 10-16 bytes around that position and use the Convert class's ToBase64String method to tranform it into a token the user can record and send to you for analysis.
Other than that I'd need more info about the type of info you're expecting to catch.
Recrehal
GenericName1
Regex.Match(textfile, "( :Name:\s( <name>[a-zA-z\s]))").Success
'' Then you can use the values from the RegExp to populate your text boxes.
txtName.Text = Match.Groups("name").value
DogCatFish