I was just playing around with error handling and put this code on a
button

Dim sng1 As Single

Try
sng1 = 1/0
MessageBox.Show(sng1.ToString)
Catch ex As Exception
MessageBox.Show(ex.Message, ex.TargetSite.Name
End Try

To my dismay, the divide by zero doe not throw an exception and the
message box displays the word Infinity...why is this? I feel really
dumb right about now...but what can I say...

TIA
John

Re: Feeling really dumb...divide by 0 by Herfried

Herfried
Mon Mar 14 13:30:32 CST 2005

"J L" <john@marymonte.com> schrieb:
>I was just playing around with error handling and put this code on a
> button
>
> Dim sng1 As Single
>
> Try
> sng1 = 1/0
> MessageBox.Show(sng1.ToString)
> Catch ex As Exception
> MessageBox.Show(ex.Message, ex.TargetSite.Name
> End Try
>
> To my dismay, the divide by zero doe not throw an exception and the
> message box displays the word Infinity...why is this? I feel really
> dumb right about now...but what can I say...

Use 'If Single.IsInfinity(sng1) Then...' to check the result.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Re: Feeling really dumb...divide by 0 by J

J
Mon Mar 14 13:36:00 CST 2005


I can do that but I dont understand why it did not throw an
exception...isn't dividing by 0 an error that should throw an
exception?

Thanks,
John

On Mon, 14 Mar 2005 20:30:32 +0100, "Herfried K. Wagner [MVP]"
<hirf-spam-me-here@gmx.at> wrote:

>"J L" <john@marymonte.com> schrieb:
>>I was just playing around with error handling and put this code on a
>> button
>>
>> Dim sng1 As Single
>>
>> Try
>> sng1 = 1/0
>> MessageBox.Show(sng1.ToString)
>> Catch ex As Exception
>> MessageBox.Show(ex.Message, ex.TargetSite.Name
>> End Try
>>
>> To my dismay, the divide by zero doe not throw an exception and the
>> message box displays the word Infinity...why is this? I feel really
>> dumb right about now...but what can I say...
>
>Use 'If Single.IsInfinity(sng1) Then...' to check the result.


Re: Feeling really dumb...divide by 0 by Christopher

Christopher
Mon Mar 14 14:16:40 CST 2005

This may give you the info you're after:
http://visualbasic.about.com/od/usingvbnet/l/bldyknaninfa.htm

J L wrote on 3/14/2005 :
> I can do that but I dont understand why it did not throw an
> exception...isn't dividing by 0 an error that should throw an
> exception?
>
> Thanks,
> John
>
> On Mon, 14 Mar 2005 20:30:32 +0100, "Herfried K. Wagner [MVP]"
> <hirf-spam-me-here@gmx.at> wrote:
>
>> "J L" <john@marymonte.com> schrieb:
>>> I was just playing around with error handling and put this code on a
>>> button
>>>
>>> Dim sng1 As Single
>>>
>>> Try
>>> sng1 = 1/0
>>> MessageBox.Show(sng1.ToString)
>>> Catch ex As Exception
>>> MessageBox.Show(ex.Message, ex.TargetSite.Name
>>> End Try
>>>
>>> To my dismay, the divide by zero doe not throw an exception and the
>>> message box displays the word Infinity...why is this? I feel really
>>> dumb right about now...but what can I say...
>>
>> Use 'If Single.IsInfinity(sng1) Then...' to check the result.

--
--------------------------------------------------
Christopher C. Bernholt
I.T. Research & Development
.NET Re-Engineering Team
R & L Carriers, Inc.
http://www.gorlc.com
--------------------------------------------------


Re: Feeling really dumb...divide by 0 by Morten

Morten
Mon Mar 14 14:24:52 CST 2005

Hi J L,

From the documentations

"Dividing a floating-point value by zero will result in either positive
infinity, negative infinity, or Not-a-Number (NaN) according to the rules
of IEEE 754 arithmetic."


--
Happy Coding!
Morten Wennevik [C# MVP]

Re: Feeling really dumb...divide by 0 by J

J
Mon Mar 14 15:04:35 CST 2005

Hi Christopher,
Thank you. That explains it. Seems strainge and counter-productive to
me but that is the way it is.

John

On Mon, 14 Mar 2005 15:16:40 -0500, "Christopher C. Bernholt"
<cbernholt@ATrlcarriers.com> wrote:

>This may give you the info you're after:
>http://visualbasic.about.com/od/usingvbnet/l/bldyknaninfa.htm
>
>J L wrote on 3/14/2005 :
>> I can do that but I dont understand why it did not throw an
>> exception...isn't dividing by 0 an error that should throw an
>> exception?
>>
>> Thanks,
>> John
>>
>> On Mon, 14 Mar 2005 20:30:32 +0100, "Herfried K. Wagner [MVP]"
>> <hirf-spam-me-here@gmx.at> wrote:
>>
>>> "J L" <john@marymonte.com> schrieb:
>>>> I was just playing around with error handling and put this code on a
>>>> button
>>>>
>>>> Dim sng1 As Single
>>>>
>>>> Try
>>>> sng1 = 1/0
>>>> MessageBox.Show(sng1.ToString)
>>>> Catch ex As Exception
>>>> MessageBox.Show(ex.Message, ex.TargetSite.Name
>>>> End Try
>>>>
>>>> To my dismay, the divide by zero doe not throw an exception and the
>>>> message box displays the word Infinity...why is this? I feel really
>>>> dumb right about now...but what can I say...
>>>
>>> Use 'If Single.IsInfinity(sng1) Then...' to check the result.