SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    referring to current line number

    Hey everyone! :-)

    Does anyone know of some way of referring to the current line number in a javascript? This would be a handy debugging tool: whenever a function threw an exception, it could say "ERG! Something wrong on THIS line".

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use then when I'm debugging in IE. It's the same information in the regular error window, this just alerts it to you which is easier than checking it by hand.
    Code:
    window.onerror = function( msg, url, line )
    {
       var a = ["An error was thrown and caught\n"];
       a.push( "Error: " + msg );
       a.push( "Line: " + line );
       a.push( "URL: " + url );
       alert( a.join( "\n" ) );
       return false;
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, great! Thanks for the code, I'll give it a go :-)

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or (assuming you're debugging in IE) you could just install Microsoft Script Debugger, which does the job very nicely indeed - it takes you directly to the highlighted code...

    Download links:
    Win9x/Me WinNT/2K/XP
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •