|
-
Nov 2nd, 2005, 02:21 PM
#1
Thread Starter
Addicted Member
Exceptions - Can you detect the line number on the form?
Is it possible to find detect the line number on which an error occures on a form?
Code:
' yadda is the line number
Try
... stuff
Catch ex As Exception
MsgBox(ex.Message & " on line number " & yadda , MsgBoxStyle.Critical, "Run Time Error ... ")
Finally
Me.Close()
End Try
I've gotten sort of spoiled using PHP for web programming and run time errors are easy to correct because PHP returns the exact line number the error is on. Would be nice to be able to get vb.net to do this too.
-
Nov 2nd, 2005, 02:30 PM
#2
Re: Exceptions - Can you detect the line number on the form?
Yes, use the ex.StackTrace to get the line number of the exception.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 2nd, 2005, 02:48 PM
#3
Re: Exceptions - Can you detect the line number on the form?
just keep in mind that stack trace will probably not give you info on the line number if you're in release mode
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Nov 2nd, 2005, 04:26 PM
#4
Re: Exceptions - Can you detect the line number on the form?
I looked it up and it doesnt mention anything about debug vs. release mode. Hmm... probably still shows.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 2nd, 2005, 04:28 PM
#5
Re: Exceptions - Can you detect the line number on the form?
I think I tried it once and it didnt work...
it "shouldnt" because compiled code doesn't understand what line numbers mean
I dont have access to Vb.net right now, but someone should give it a try
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Nov 2nd, 2005, 07:02 PM
#6
Re: Exceptions - Can you detect the line number on the form?
The stack trace will not give you line numbers because, as stated, there are no line numbers in compiled code. It will give you the the fully qualified name of the method in which the exception was thrown though, so how hard can it be to find?
-
Nov 2nd, 2005, 08:39 PM
#7
Re: Exceptions - Can you detect the line number on the form?
It can be realy really really hard if you have a huge procedure.
Thanks for doing the verification John.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 2nd, 2005, 08:44 PM
#8
Re: Exceptions - Can you detect the line number on the form?
 Originally Posted by RobDog888
It can be realy really really hard if you have a huge procedure.
That's quite true and I've experienced that myself, which is one of the reasons I have now sworn to always follow the "rule" of keeping methods short and farming out chunks to their own methods.
-
Nov 2nd, 2005, 08:51 PM
#9
Re: Exceptions - Can you detect the line number on the form?
Now what would happen if you had a large procedure broken down into smaller procedure calls from the main on and the main one was the only one with a Try Catch? Would the StackTrace show one of the child sub procedures if the error was caused in it?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 2nd, 2005, 09:01 PM
#10
Re: Exceptions - Can you detect the line number on the form?
You'll note that the stack trace shown in my images includes the calls to the Framework itself, which shows that it goes right to the deepest point within the managed code. Unmanaged code is another story I think. For aditional proof se the attached image. Also note that line numbers are shown for the debug code but not for the Framework calls, which are release compiled.
-
Nov 3rd, 2005, 04:21 PM
#11
Re: Exceptions - Can you detect the line number on the form?
 Originally Posted by jmcilhinney
The stack trace will not give you line numbers because, as stated, there are no line numbers in compiled code. It will give you the the fully qualified name of the method in which the exception was thrown though, so how hard can it be to find?
good point too
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|