Break when the exception is thrown and IsNumeric

G

Guest

Hi all,

I don't think a solution exists, but maybe there is some option in Visual
Studio that I do not know about.

When developping (or debugging), I like to set the "exceptions" option to
"break when the error is thrown", even for handled exceptions, because a
general purpose error handler usually handles all unexpected exceptions.

A side effect of that is that a break also happens when an exception occurs
inside a function that is not in my code, for example when the IsNumeric
function is called with an argument that is not numeric, or when IsDate is
called when an argument that is not a date.

If someone would know how to avoid this, then I would appreciate it if you
could share it here. I know I can modify the setting for each exception type
(FormatException in case of the IsNumeric function), but I don't want to do
that, because that also would change the behaviour of those exception when
resulting from my own code.

Thanks in advance,

Joris
 
N

Nick Malik [Microsoft]

Joris Zwaenepoel said:
Hi all,

I don't think a solution exists, but maybe there is some option in Visual
Studio that I do not know about.

When developping (or debugging), I like to set the "exceptions" option to
"break when the error is thrown", even for handled exceptions, because a
general purpose error handler usually handles all unexpected exceptions.

A side effect of that is that a break also happens when an exception
occurs
inside a function that is not in my code, for example when the IsNumeric
function is called with an argument that is not numeric, or when IsDate is
called when an argument that is not a date.

If someone would know how to avoid this, then I would appreciate it if you
could share it here. I know I can modify the setting for each exception
type
(FormatException in case of the IsNumeric function), but I don't want to
do
that, because that also would change the behaviour of those exception when
resulting from my own code.

You should not be throwing system exceptions from within your own code. You
should be throwing application exceptions from within your code. If you fix
your own mistake first, you will have no problem avoiding the behavior that
you dislike in Visual Studio.


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
C

Cor Ligthert [MVP]

Joris,

You can catch those errors by setting this in the debug options. You can
fine tune this setting depending on your own need.

In version 2002/2003 you find this information in
Debug -> Exceptions

In version 2005 I don't know where they have hide it, but you can get it in
the project with
ctrl alt E

I hope this helps,

Cor
 
G

Guest

Nick,

Do you mean that I should not throw exception types like
"ArgumentOutOfRangeException" or "ArgumentException" or even
"FormatException" from my own class libraries?

I understand that I can create custom exception types, derived from
ApplicationException, but I do not understand why throwing one of these
framework exception types would be a mistake. For example, if an argument is
passed with a value of null (or Nothing), what is wrong with throwing an
ArgumentNullException?

Joris
 
G

Guest

Cor,

Thanks for trying to help. I know where to fine-tune the settings, but what
I really want is that the break only happens when the error is thrown and
bubbles up to the my code that calls that procedure.

I don't care if IsNumeric and IsDate use an exception in their
implementation, I use it because those function to validate data. I can
disable the "break when the exception is thrown" setting for those exception
types, but then this is disabled also when the same exception type is not
handled inside the called procedure but because of my own exception handling
logic.

I hope my explanation is clear, if not, I can try to create a small
code-example.

I don't think it is possible in VS2003, and probably not in VS2005 either,
but there are more options available that I don't know of, and I was hoping
that would be the case here.

Joris
 
C

Cor Ligthert [MVP]

Joris,

Did you try those debug options, they can (need to) be very much fine tuned.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top