.NETGURU
System.DivideByZeroException does not catch exception
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.

Post a new message to this list...

Amin Sobati
Hi,
I have the following code in my app:

Dim intx As Integer
Dim inty As Integer
Dim intz As Integer
inty = 0
intx = 5
Try
intz = intx / inty
Catch ex As System.DivideByZeroException
MsgBox("Catch")
End Try

But System.DivideByZeroException does not catch the exception. If I use
System.OverflowException it will work.
What's the reason?
Thanks,
Amin

Reply to this message...
 
    
Dot Net Guruias Sjögren
[Original message clipped]

The reason is that the / operator performs floating point division,
which doesn't throw a DivideByZeroException but rather returns NaN or
Infinity. If you turn on Option Strict this whould be more visible
since converting the result back to an Integer is a narrowing
conversion.

The solution may be to use the integer division operator \ instead.

Dot Net Guruias

--
Dot Net Guruias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Reply to this message...
 
    
Amin Sobati
Thanks Dot Net Guruias!
It was great tip :-)
Amin

"Dot Net Guruias Sjögren" <Click here to reveal e-mail address> wrote in message
news:u#Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.DivideByZeroException
System.OverflowException




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification