473,486 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Explicitly throw an exception in VB.NET


I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.

In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?

Aug 10 '07 #1
6 3379
On Aug 10, 9:36 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.

In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?
Exceptions will bubble up automatically unless you have the debugger
attached. With the debugger attached and unhandled exceptions will
cause execution to stop and put the debugger in step-through mode. You
can set what the debugger does with different types of exceptions
using the Exceptions window (found under the Debug menu).

If you want to see what would happen when the application doesn't have
the debugger attached you can run the app by pressing Ctrl+F5.

Thanks,

Seth Rowe

Aug 10 '07 #2
On Aug 10, 2:48 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Aug 10, 9:36 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.
In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?

Exceptions will bubble up automatically unless you have the debugger
attached. With the debugger attached and unhandled exceptions will
cause execution to stop and put the debugger in step-through mode. You
can set what the debugger does with different types of exceptions
using the Exceptions window (found under the Debug menu).

If you want to see what would happen when the application doesn't have
the debugger attached you can run the app by pressing Ctrl+F5.

Thanks,

Seth Rowe
I understand the debugger, My question is when debugger catches the
exception, instead of me manually going to the call stack and finding
the correct place the data became corrupt, can I simply tell the
debugger to "not handle exceptions" until they esculate above that
level. Does that make sense? Basically all the code at the bottom is
trust-worthy decent code, can I exclude the debugger from stepping
into it and can I exclude the code from being stopped inside those
functions?

Aug 10 '07 #3
Phillip,

In .Net, if an exception occurs in a method that is not equipped to handle
it, the exception is propagated back to the calling method. If the calling
method also has no exception handler, the exception is propagated back to
that method 's caller, and so on. If no exception handler is found, an error
message is displayed and the application is terminated.

Perhaps in the IDE you are breaking whenever an exception is thrown. You can
change this behavior from the IDE's Debug menu, under the Exception item.

Kerry Moorman
"Phillip Taylor" wrote:
>
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.

In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?

Aug 10 '07 #4
On Aug 10, 9:54 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
On Aug 10, 2:48 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Aug 10, 9:36 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.
In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?
Exceptions will bubble up automatically unless you have the debugger
attached. With the debugger attached and unhandled exceptions will
cause execution to stop and put the debugger in step-through mode. You
can set what the debugger does with different types of exceptions
using the Exceptions window (found under the Debug menu).
If you want to see what would happen when the application doesn't have
the debugger attached you can run the app by pressing Ctrl+F5.
Thanks,
Seth Rowe

I understand the debugger, My question is when debugger catches the
exception, instead of me manually going to the call stack and finding
the correct place the data became corrupt, can I simply tell the
debugger to "not handle exceptions" until they esculate above that
level. Does that make sense? Basically all the code at the bottom is
trust-worthy decent code, can I exclude the debugger from stepping
into it and can I exclude the code from being stopped inside those
functions?
Reread my post - I said you could use the Exceptions tool under the
Debug menu to set which types of exceptions the debugger will break
on.

Thanks,

Seth Rowe

Aug 10 '07 #5
On Aug 10, 3:20 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Aug 10, 9:54 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
On Aug 10, 2:48 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Aug 10, 9:36 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.
In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?
Exceptions will bubble up automatically unless you have the debugger
attached. With the debugger attached and unhandled exceptions will
cause execution to stop and put the debugger in step-through mode. You
can set what the debugger does with different types of exceptions
using the Exceptions window (found under the Debug menu).
If you want to see what would happen when the application doesn't have
the debugger attached you can run the app by pressing Ctrl+F5.
Thanks,
Seth Rowe
I understand the debugger, My question is when debugger catches the
exception, instead of me manually going to the call stack and finding
the correct place the data became corrupt, can I simply tell the
debugger to "not handle exceptions" until they esculate above that
level. Does that make sense? Basically all the code at the bottom is
trust-worthy decent code, can I exclude the debugger from stepping
into it and can I exclude the code from being stopped inside those
functions?

Reread my post - I said you could use the Exceptions tool under the
Debug menu to set which types of exceptions the debugger will break
on.

Thanks,

Seth Rowe
I understand the concept of exceptions....if I don't catch it in the
"ExecuteSQLCommand" it propogates up the callstack until it finds a
Try Catch block around it. I understand I can catch and throw
exceptions anywhere. I understand if the debugger is off and there is
no exception handling code then the application will crash and
the .NET runtime will show an error message and end my application. I
understand exceptions completely. What I don' t understand is that if
this is my call stack looks like this:

button_click
- eventListener
-- custom code
--- ExecuteSQLCommand

how I can make the exception, which I don't want to catch or handle,
that could be any subclass of the exception object, will take the
debugger and instead of stopping it on the "ExecuteSQLCommand"
function, I can make it stop in the "custom code" function instead, on
the line at which it calls ExecuteSQLCommand.

In Java I can declaire "ExecuteSQLCommand" like this "public int
ExecuteSQLCommand(String sql) THROWS EXCEPTION" and the debugger moves
me to "custom code" level rather than the "ExecuteSQLStatement" level.

Can I do something similar in VB.NET? Don't take me to here with the
debugger....but take me to this level in the call stack instead?

Aug 10 '07 #6
On Aug 10, 12:06 pm, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
On Aug 10, 3:20 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Aug 10, 9:54 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
On Aug 10, 2:48 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Aug 10, 9:36 am, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL queries
data passed to it. I don't want to handle or supress exceptions at
that point in the application, but rather ignore them so the debugger
handles them in the correct place, further up the call stack.
In java I could normally add a "throws Exception" to the end of the
function definitiion. Does anyone know how do I do the same thing in
VB?
Exceptions will bubble up automatically unless you have the debugger
attached. With the debugger attached and unhandled exceptions will
cause execution to stop and put the debugger in step-through mode. You
can set what the debugger does with different types of exceptions
using the Exceptions window (found under the Debug menu).
If you want to see what would happen when the application doesn't have
the debugger attached you can run the app by pressing Ctrl+F5.
Thanks,
Seth Rowe
I understand the debugger, My question is when debugger catches the
exception, instead of me manually going to the call stack and finding
the correct place the data became corrupt, can I simply tell the
debugger to "not handle exceptions" until they esculate above that
level. Does that make sense? Basically all the code at the bottom is
trust-worthy decent code, can I exclude the debugger from stepping
into it and can I exclude the code from being stopped inside those
functions?
Reread my post - I said you could use the Exceptions tool under the
Debug menu to set which types of exceptions the debugger will break
on.
Thanks,
Seth Rowe

I understand the concept of exceptions....if I don't catch it in the
"ExecuteSQLCommand" it propogates up the callstack until it finds a
Try Catch block around it. I understand I can catch and throw
exceptions anywhere. I understand if the debugger is off and there is
no exception handling code then the application will crash and
the .NET runtime will show an error message and end my application. I
understand exceptions completely. What I don' t understand is that if
this is my call stack looks like this:

button_click
- eventListener
-- custom code
--- ExecuteSQLCommand

how I can make the exception, which I don't want to catch or handle,
that could be any subclass of the exception object, will take the
debugger and instead of stopping it on the "ExecuteSQLCommand"
function, I can make it stop in the "custom code" function instead, on
the line at which it calls ExecuteSQLCommand.

In Java I can declaire "ExecuteSQLCommand" like this "public int
ExecuteSQLCommand(String sql) THROWS EXCEPTION" and the debugger moves
me to "custom code" level rather than the "ExecuteSQLStatement" level.

Can I do something similar in VB.NET? Don't take me to here with the
debugger....but take me to this level in the call stack instead?
How about:

Public Sub CustomCode()
ExecuteSqlCommand("Select * From WhereEver")
End Sub

Public Sub ExecuteSqlCommand(sql as String)
Try
'// Normal code here
Catch
Throw
End Try
End Sub

IIRC the debugger breaks where an exception is unhandled. The
try...catch...throw in the ExecuteSqlCommand sub should be marked as
handling the exception meaning the debugger will stop once the
exception bubbles back up to CustomCode.

I haven't tested this - so please let me know what happens either way.

Thanks,

Seth Rowe

Aug 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
458
by: Kerri | last post by:
Hi, I am new to .NET In my Error Logic on my Aspx pages when an error happens it hits my catch statement where I throw an Exception. My question is : what is the difference between Thwo...
4
1960
by: Eric Lilja | last post by:
Hello, in my program I have a function (pseudo code): void start_mysql_service() { obtain handle start mysql service using handle if start fails close handle and throw an exception...
3
3479
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
0
1138
by: Lasse Vågsæther Karlsen | last post by:
From the book by Jeffrey Richter: throw; will not change the origin of the exception, whereas throw ex; will change the origin of the exception to this statement. When I try the following...
17
1925
by: hplloyd | last post by:
Hi, I have a function that adds data to a database and I want to return true if the database was updated and false if there was a problem, so I am using a try... catch block... My problem is...
6
11624
by: Henryk | last post by:
I did a lot of delphi GUI programming recently. In my experience most of the time you just want to throw a standard exception with a descriptive message. Then all calling functions can handle...
5
1949
by: nospam_news | last post by:
When language changes make old code uncompilable, that's not what is called protection of investment. New compilers (g++ 3.2.3) reject classes where methods throw the class they belong to. gcc...
28
2815
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't...
6
1940
by: jason.cipriani | last post by:
Consider this program, which defines a template class who's template parameter is the type of an exception that can be thrown by members of the class: === BEGIN EXAMPLE === #include...
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.