Go Back   Java Programming Forums > Java Standard Edition Programming Help > Exceptions


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 22-05-2010, 03:04 PM
Member
 

Join Date: May 2010
Posts: 38
Thanks: 1
Thanked 8 Times in 7 Posts
Lord.Quackstar is on a distinguished road

I'm feeling Hungover
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; 22-05-2010 at 04:10 PM. Reason: Added cross-post notification
Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 22-05-2010, 05:57 PM
Member
 

Join Date: Nov 2008
Posts: 121
Thanks: 0
Thanked 4 Times in 4 Posts
dlorde is on a distinguished road
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.
Reply With Quote
  #3 (permalink)  
Old 22-05-2010, 06:57 PM
Member
 

Join Date: May 2010
Posts: 38
Thanks: 1
Thanked 8 Times in 7 Posts
Lord.Quackstar is on a distinguished road

I'm feeling Hungover
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.
Reply With Quote
  #4 (permalink)  
Old 23-05-2010, 01:35 AM
Member
 

Join Date: Nov 2008
Posts: 121
Thanks: 0
Thanked 4 Times in 4 Posts
dlorde is on a distinguished road
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)...

Quote:
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
Reply With Quote
  #5 (permalink)  
Old 24-05-2010, 07:59 AM
Json's Avatar
Super Moderator
 

Join Date: Jul 2009
Location: Manchester, United Kingdom
Posts: 1,190
Thanks: 57
Thanked 137 Times in 133 Posts
Json will become famous soon enoughJson will become famous soon enoughJson will become famous soon enough

I'm feeling Happy
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
Reply With Quote
  #6 (permalink)  
Old 24-05-2010, 11:34 AM
Member
 

Join Date: May 2010
Posts: 38
Thanks: 1
Thanked 8 Times in 7 Posts
Lord.Quackstar is on a distinguished road

I'm feeling Hungover
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.
Reply With Quote
  #7 (permalink)  
Old 25-05-2010, 07:15 AM
Json's Avatar
Super Moderator
 

Join Date: Jul 2009
Location: Manchester, United Kingdom
Posts: 1,190
Thanks: 57
Thanked 137 Times in 133 Posts
Json will become famous soon enoughJson will become famous soon enoughJson will become famous soon enough

I'm feeling Happy
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
Reply With Quote
Reply

Tags
ecmaerror, exception, jsr223

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vectors - accessing an unknown amount of objects fox Loops & Control Statements 1 07-05-2010 08:54 PM
What can go wrong if you replace && with & in the following code: scott01 Java Theory & Questions 4 12-02-2010 11:47 AM
Jsp source not found jadeite100 What's Wrong With My Code? 0 15-01-2010 05:00 AM
Website Source expertOpinion Java Theory & Questions 10 21-07-2009 04:06 PM
[SOLVED] books or source for beginners chronoz13 Java Theory & Questions 1 15-04-2009 01:36 PM


100 most searched terms
Search Cloud
2359-unable-move action listener in java actionlistener actionlistener in java addactionlistener addactionlister adding elements to two dimensional arraylist in java cannot find symbol method create an abstract class called shape with abstract methods+java double to integer double to integer in java double to integer java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread main java.lang.outofmemoryerror java heap space in eclipse get files from folder java by threads get mouse position java how to convert list to map in java http://www.javaprogrammingforums.com/collections-generics/2688-grade-array-trouble.html http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html iphone java java actionlistener java cos java double format java double to int java font attributes java format double java forum java forums java get mouse position java heap size exception java jbutton java nextline() java programming codes using astirisks java programming forum java programming forums java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space jbutton actionlistener jbutton with key enter jtable questions in java jtext bold jtextarea font jxl.read.biff.biffexception: unable to recognize ole stream mean value decimal double java oops java assignments programmer forum transaction using gui and 2 dimensional array code in java two dimensional arraylist in java typecast in java

All times are GMT. The time now is 09:37 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.