|
|
#1 |
|
Fanatic Member
Join Date: Oct 08
Location: Dominican Republic
Posts: 732
![]() |
Hello,
I'm wondering if there is any way to know where did the error come from. I have this: vb.net Code:
When I say "where did the error come from, is which case threw the error.I know I could check the values and throw an exception, but I want to know which case produced the exception. I hope it's clear .Thanks in advance! PS: That's just an example.
__________________
"In our profession, precision and perfection are not a dispensable luxury, but a simple necessity." Niklaus E. Wirth Rate any post that helped you, it's a good way of saying thanks ![]() Please specify your Visual Studio Version! Why rating is useful My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary |
|
|
|
|
|
#2 |
|
Frenzied Member
Join Date: Apr 04
Location: Gardnerville,nv
Posts: 1,443
![]() ![]() |
Re: Error handling question... Where did it come from?
You can get the line number through the exception's StackTrace property, but to get the actual case, you would probably need to do a second case select in the exception block
vb Code:
__________________
It's too hard to read code that is not wrapped in code tags, so I don't. Use code tags around your code segments Thank you for your support. -Bartyles & James (circa 1980) And in knowing that you know nothing, that makes you the smartest of all. - Socrates (469 BC - 399 BC) ________________________________________________________________ Last edited by kebo : Now. Reason: superfluous typo's |
|
|
|
|
|
#3 |
|
Fanatic Member
Join Date: Oct 08
Location: Dominican Republic
Posts: 732
![]() |
Re: Error handling question... Where did it come from?
Oh great!!! THANKS!!!
__________________
"In our profession, precision and perfection are not a dispensable luxury, but a simple necessity." Niklaus E. Wirth Rate any post that helped you, it's a good way of saying thanks ![]() Please specify your Visual Studio Version! Why rating is useful My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary |
|
|
|
|
|
#4 |
|
Learning .Net
Join Date: Aug 04
Location: VBForums
Posts: 5,016
![]() ![]() ![]() ![]() ![]() ![]() |
Re: Error handling question... Where did it come from?
You have to get the details from the Stack Trace Only.
I won't go with the method suggested by kebo, though it is good. This will increase the complexity of the Program. As you have the MathOperation varriable in the Try block you can always check the text of this varriable and get the case which cause the Exception as Code:
Dim MathOperation As String = "Divide"
Try
Select Case MathOperation
Case "Divide"
Dim x As Integer = Convert.ToInt16("D")
Case "Multiply"
'Multiply a*b
'Calculate tangent
End Select
Catch ex As Exception
MessageBox.Show("Error came from " & MathOperation)
End Try
__________________
Please mark you thread resolved using the Thread Tools as shown ![]() If my post was helpful to you, then Rate it ![]() www.techreceipe.com Tier Architecture |
|
|
|
|
|
#5 |
|
Frenzied Member
Join Date: Apr 04
Location: Gardnerville,nv
Posts: 1,443
![]() ![]() |
Re: Error handling question... Where did it come from?
yea... that would certainly simplify things
__________________
It's too hard to read code that is not wrapped in code tags, so I don't. Use code tags around your code segments Thank you for your support. -Bartyles & James (circa 1980) And in knowing that you know nothing, that makes you the smartest of all. - Socrates (469 BC - 399 BC) ________________________________________________________________ Last edited by kebo : Now. Reason: superfluous typo's |
|
|
|
|
|
#6 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 60,536
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Error handling question... Where did it come from?
Depending on what you actually intend to do in the Catch block, a separate exception handler for each Case might be the most appropriate option.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
#7 |
|
Fanatic Member
Join Date: Oct 08
Location: Dominican Republic
Posts: 732
![]() |
Re: Error handling question... Where did it come from?
Ok, thanks a lot guys
.
__________________
"In our profession, precision and perfection are not a dispensable luxury, but a simple necessity." Niklaus E. Wirth Rate any post that helped you, it's a good way of saying thanks ![]() Please specify your Visual Studio Version! Why rating is useful My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|