2 Replies - 598 Views - Last Post: 27 June 2013 - 09:45 PM Rate Topic: -----

#1 jdgreat39  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-June 13

NotFiniteNumberException

Posted 27 June 2013 - 08:03 PM

I am new to programming, so apologies in advance for very basic mistakes. I'm trying to create an instance of the NotFiniteNumberException where A is the maximum value and b is greater than that. The program in it's current state does not pick up the exception and comes back with "1" and "Result is 1". My desired result is for the exception to be called upon and for the text "b is above the Max Value" to appear. Any help would be appreciated. Thank you!

Module Module1

    Public Sub Main()
        Dim a As Integer = Integer.MaxValue = 5

        Dim b As Integer = a + 1

        Try
           
            System.Console.WriteLine(B)/>/>

        Catch ex As NotFiniteNumberException
            System.Console.WriteLine("b is above the Max Value.")

        Finally

            System.Console.WriteLine("Result is {0}", B)/>/>


        End Try
        System.Console.ReadKey()

    End Sub

End Module



Is This A Good Question/Topic? 0
  • +

Replies To: NotFiniteNumberException

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,054
  • Joined: 02-July 08

Re: NotFiniteNumberException

Posted 27 June 2013 - 09:17 PM

Turn Option Strict On. Here is how the compiler read this line:

Dim a As Integer = Integer.MaxValue = 5


Reads:

Dim a As Integer = (Integer.MaxValue = 5)
' boolean check - does Integer.MaxValue = 5
' so can't convert an integer to boolean


Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: NotFiniteNumberException

Posted 27 June 2013 - 09:45 PM

Documentation for this exception states:

Quote

The exception that is thrown when a floating-point value is positive infinity, negative infinity, or Not-a-Number (NaN).

Integer.MaxValue is a constant that returns the largest value of an Integer. In the case of a 32 bit integer, for example, this constant has a value of 2,147,483,647, or hexadecimal 0x7FFFFFFF.

This post has been edited by lar3ry: 27 June 2013 - 09:49 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1