Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

  1. #1
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    Hello everyone,

    In my code, I have a bunch of scripts contained in .js files. Whenever one of the scripts contains an error, I get this:

    javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "nonexistant" is not defined. (<Unknown source>#5) in <Unknown source> at line number 5

    What bugs me is the <Unknown Source>. Multiple files are in one ScriptContext, and it can be hard to track down an error. It also looks horrible.

    Is there a way to replace <Unknown Source> with the actual file name? None of the methods I see support passing a File object, so I'm really confused here.

    Mirrored at Replace <Unknown Source> in Java Rhino (JSR223) with actual file name - Stack Overflow
    Last edited by Lord.Quackstar; May 22nd, 2010 at 11:10 AM. Reason: Added cross-post notification


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    The file name, line number, and variable name info are included in the class files when compiled with the debug option -g. The JVM exception management can then pick them up from the class files at runtime to provide more informative messages. See Java Compiler Options.

  3. #3
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    Quote Originally Posted by dlorde View Post
    The file name, line number, and variable name info are included in the class files when compiled with the debug option -g. The JVM exception management can then pick them up from the class files at runtime to provide more informative messages. See Java Compiler Options.
    You must not be familiar with ScriptEngine. The files aren't compiled, their plain JavaScript files that are dynamically loaded and parsed. And that's not a compile error, thats a runtime error.

  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    Quote Originally Posted by Lord.Quackstar View Post
    You must not be familiar with ScriptEngine.
    You're right, I'm not (well, not that familiar)...

    The files aren't compiled, their plain JavaScript files that are dynamically loaded and parsed. And that's not a compile error, thats a runtime error.
    I wasn't suggesting it was a compiler error, I was just saying that in order to get the filename and line number of Java source in exception messages, the javac -g debug options should be used when compiling Java source code. Clearly this will only tell you the last Java class file and line executed, not JavaScript innards, but I thought this was a Java question. If it doesn't apply here, then I'm sorry, it won't help

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    Any chance you can run your Javascript code in a normal browser by including it from a dummy HTML file, that way you could use the browsers Javascript debugger which is probably a lot better than your Java IDE

    // Json

  6. #6
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    Quote Originally Posted by Json View Post
    Any chance you can run your Javascript code in a normal browser by including it from a dummy HTML file, that way you could use the browsers Javascript debugger which is probably a lot better than your Java IDE

    // Json
    That would be probably the best way, but the issue though is that I also load util functions and place then at the top of the file (hence why its hard when an error like that shows up because I have no idea if its the util files or the command file).

    And also this is java scripting, not browser scripting. Surly there's support for this since EcmaError has a spot for the file name.

  7. #7
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Replace <Unknown Source> in EcmaError (JSR223) with actual file name

    Yes, point taken, I also think it should give you a nicer message than Unknown Source, is there anyway through the ScriptEngine you can set a debug flag of some kind?

    I'm not too familiar with the ScriptEngine myself you see.

    // Json

Similar Threads

  1. Vectors - accessing an unknown amount of objects
    By fox in forum Loops & Control Statements
    Replies: 1
    Last Post: May 7th, 2010, 03:54 PM
  2. What can go wrong if you replace && with & in the following code:
    By scott01 in forum Java Theory & Questions
    Replies: 4
    Last Post: February 12th, 2010, 06:47 AM
  3. Jsp source not found
    By jadeite100 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 15th, 2010, 12:00 AM
  4. Website Source
    By expertOpinion in forum Java Theory & Questions
    Replies: 10
    Last Post: July 21st, 2009, 11:06 AM
  5. [SOLVED] Books and sources for Java beginners
    By chronoz13 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 15th, 2009, 08:36 AM

Tags for this Thread