Exception Class Question -> getLine()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Seamus M

    Exception Class Question -> getLine()

    It seems when I use the getLine() method of the Exception class, it returns
    the line number of the "throw new Exception" statement and not the line
    number where the error actually occured in the source file. Am I doing
    something wrong?

    - Seamus


  • Jerry Stuckle

    #2
    Re: Exception Class Question -> getLine()

    Seamus M wrote:[color=blue]
    > It seems when I use the getLine() method of the Exception class, it returns
    > the line number of the "throw new Exception" statement and not the line
    > number where the error actually occured in the source file. Am I doing
    > something wrong?
    >
    > - Seamus
    >
    >[/color]

    How is the exception supposed to know where the error occurred? It
    could have been anything - bad return code, incorrect data, whatever.
    But in all cases, it's something you had to detect. This might have
    been many lines of code before you actually threw the exception, or even
    in a different (included) file.

    All the exception can tell is where you threw it.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Seamus M

      #3
      Re: Exception Class Question -> getLine()

      It appears the exception should be thrown on the line immediately after the
      potenially error causing code for "getLine()" to be any use. I was
      anticipating it to work like the built-in errors which tell you what line of
      code caused the error.

      Thanks for your input.

      - Seamus

      "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
      news:ov-dnYfolKwGStTeRV n-oA@comcast.com. ..[color=blue]
      > Seamus M wrote:[color=green]
      >> It seems when I use the getLine() method of the Exception class, it
      >> returns the line number of the "throw new Exception" statement and not
      >> the line number where the error actually occured in the source file. Am
      >> I doing something wrong?
      >>
      >> - Seamus[/color]
      >
      > How is the exception supposed to know where the error occurred? It could
      > have been anything - bad return code, incorrect data, whatever. But in all
      > cases, it's something you had to detect. This might have been many lines
      > of code before you actually threw the exception, or even in a different
      > (included) file.
      >
      > All the exception can tell is where you threw it.
      >
      > --
      > =============== ===
      > Remove the "x" from my email address
      > Jerry Stuckle
      > JDS Computer Training Corp.
      > jstucklex@attgl obal.net
      > =============== ===[/color]


      Comment

      • Jerry Stuckle

        #4
        Re: Exception Class Question -&gt; getLine()

        Seamus M wrote:[color=blue]
        > It appears the exception should be thrown on the line immediately after the
        > potenially error causing code for "getLine()" to be any use. I was
        > anticipating it to work like the built-in errors which tell you what line of
        > code caused the error.
        >
        > Thanks for your input.
        >
        > - Seamus
        >
        > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
        > news:ov-dnYfolKwGStTeRV n-oA@comcast.com. ..
        >[color=green]
        >>Seamus M wrote:
        >>[color=darkred]
        >>>It seems when I use the getLine() method of the Exception class, it
        >>>returns the line number of the "throw new Exception" statement and not
        >>>the line number where the error actually occured in the source file. Am
        >>>I doing something wrong?
        >>>
        >>> - Seamus[/color]
        >>
        >>How is the exception supposed to know where the error occurred? It could
        >>have been anything - bad return code, incorrect data, whatever. But in all
        >>cases, it's something you had to detect. This might have been many lines
        >>of code before you actually threw the exception, or even in a different
        >>(included) file.
        >>
        >>All the exception can tell is where you threw it.
        >>
        >>--
        >>============= =====
        >>Remove the "x" from my email address
        >>Jerry Stuckle
        >>JDS Computer Training Corp.
        >>jstucklex@att global.net
        >>============= =====[/color]
        >
        >
        >[/color]

        There's a difference here. The built-in errors know where the error
        occurred, because they detected the error.


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Oli Filth

          #5
          Re: Exception Class Question -&gt; getLine()

          Seamus M wrote:[color=blue]
          > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
          > news:ov-dnYfolKwGStTeRV n-oA@comcast.com. ..[color=green]
          > > Seamus M wrote:[color=darkred]
          > >> It seems when I use the getLine() method of the Exception class, it
          > >> returns the line number of the "throw new Exception" statement and not
          > >> the line number where the error actually occured in the source file. Am
          > >> I doing something wrong?
          > >>[/color]
          > >
          > > How is the exception supposed to know where the error occurred? It could
          > > have been anything - bad return code, incorrect data, whatever. But in all
          > > cases, it's something you had to detect. This might have been many lines
          > > of code before you actually threw the exception, or even in a different
          > > (included) file.
          > >
          > > All the exception can tell is where you threw it.
          > >[/color]
          >
          > It appears the exception should be thrown on the line immediately after the
          > potenially error causing code for "getLine()" to be any use. I was
          > anticipating it to work like the built-in errors which tell you what line of
          > code caused the error.
          >[/color]

          I imagine you're using exceptions something like:

          ....
          if (Some Bad Condition)
          {
          throw new Exception("You fool!");
          }
          ....

          As Jerry said, the exception itself has no idea what caused the error,
          and what line that corresponds to.

          But getLine() will direct you to the throw... line, which should be
          enough of a clue to work out where the error was!

          --
          Oli

          Comment

          Working...