Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / October 2003

Tip: Looking for answers? Try searching our database.

catching Microsoft.JScript.JScriptException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bB - 17 Oct 2003 18:06 GMT
I am calling an external dll (compiled JScript) from within a
try/catch/finally block in a C# program and am unable to catch exceptions
being raised in the JScript dll by having a specific 'JScriptExcepton' catch
block. I can't work out why this is.

If I have a general catch block that catch's excpetions of type 'Exception'
and print out the type of the exception, it correctly states that the type
is 'Microsoft.JScript.JScriptException'.

I have worked around the problem by doing a string comparison as follows:

catch (Exception ex)
{
hasErrors = true;

errorString +=
 "An unexpected error has been encountered\n" +
 "whilst processing the entry for '" +

productPackageItem["Description"] + "':\n\n";

//For some reason, exceptions of type "Microsoft.JScript.JScriptException"
//are not being caught with a seperate catch handler, and a comparison
using
//ex.GetType() against this exception class are also not working. A string
//comparison seems to be the only way of differentiated it...

if (ex.GetType().ToString() == "Microsoft.JScript.JScriptException")
{
 errorString += "There is an error in the dimension formula\n\n";
}

errorString += "\"" + ex.Message + "\"";
}

What am I missing?

Tim.
Chris R. Timmons - 17 Oct 2003 20:19 GMT
> I am calling an external dll (compiled JScript) from within a
> try/catch/finally block in a C# program and am unable to catch
> exceptions being raised in the JScript dll by having a specific
> 'JScriptExcepton' catch block. I can't work out why this is.

Tim,

Which version of .Net are you using - 1.0 or 1.1?  I've had other
problems w/ JScript.Net in 1.0 that were fixed in 1.1.

Are the C# catch blocks in the correct order?  I.e.:

 try
   ...
 catch (Microsoft.JScript.JScriptException jse)
   ...
 catch (Exception ex)
   ...

For some reason it's hard to find more info on JScriptException.  The
.Net help file is mute on the subject, and MSDN is hardly better.  
You might try searching Google and MSDN for "JScriptException" to see
if those entries help.

Looking at the source code for the JScript.Net compiler (in the SSCLI
distribution), I found this in jscriptexception.cs:

 //-----------------------------------------------------------------
--------------------------------------
 // JScriptException
 //
 //  An error in JScript goes to a COM+ host/program in the form of
a JScriptException. However a
 //  JScriptException is not always thrown. In fact a
JScriptException is also a IVsaError and thus it can be
 //  passed to the host through IVsaSite.OnCompilerError(IVsaError
error).
 //  When a JScriptException is not a wrapper for some other object
(usually either a COM+ exception or
 //  any value thrown in a JScript throw statement) it takes a
JSError value.
 //  The JSError enum is defined in JSError.cs. When introducing a
new type of error perform
 //  the following four steps:
 //  1- Add the error in the JSError enum (JSError.cs)
 //  2- Update GetErrorType() to return a value from the ErrorType
enum (in ErrorConstructor) for the
 //     error you just defined. GetErrorType() is a map form JSError
to a JScript object in the Error
 //     hierarchy
 //  3- Update Microsoft.JScript.txt with the US English error
message
 //  4- Update Severity.
 //-----------------------------------------------------------------
--------------------------------------

And - from the same jscriptexception.cs file - the class signature
for JScriptException is:

[Serializable] public class JScriptException : ApplicationException,
IVsaError

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
bB - 17 Oct 2003 22:29 GMT
Chris,

Many thanks for the reply and level of detail - very instructive. I am using
.NET 1.0 (with patches...) as I am tied to VS.NET 2002 for the moment.

I have got my catches in the correct order, and was suprised that you can
nearly whack Google with the problem. I'm presuming that the framework
version may be at the root of things as you suggested.

I am perplexed that a call to ex.GetType().ToString() returns the type that
would be expected i.e "Microsoft.JScript.JScriptException", but trying:

ex.GetType() == typeof(Microsoft.JScript.JScriptException)

evaluates to false. If you attempt to cast the Exception to a
JScriptException, the whole thing blows up!

The text in jscriptexception.cs which reads:

> ... In fact a
> JScriptException is also a IVsaError and thus it can be
>   //  passed to the host through IVsaSite.OnCompilerError(IVsaError
> error).

is interesting, as the error that is being raised is the result of a failed
call to 'eval' through a wrapper. Would this error be handled by
OnCompileError and cause some side-effect???

I will investigate trapping the error and passing the JScriptException back
as an inner exception (or what-have-you) as I would like to get at the error
number.

Many Thanks, Tim.

> > I am calling an external dll (compiled JScript) from within a
> > try/catch/finally block in a C# program and am unable to catch
[quoted text clipped - 64 lines]
> C.R. Timmons Consulting, Inc.
> http://www.crtimmonsinc.com/
bB - 17 Oct 2003 22:59 GMT
If I put a break line in and do a quick-watch on "ex" it will give me access
to the JScriptException via a cast, but if I try to cast the exception in
code it blows up... Very weird.

> Chris,
>
[quoted text clipped - 98 lines]
> > C.R. Timmons Consulting, Inc.
> > http://www.crtimmonsinc.com/

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.