You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Robby Pelssers, AGP" <ro...@agp.nl> on 2007/01/09 17:10:30 UTC

how to catch and throw exceptions in cocoon2.1.10 (javascript)

Hi,
 
I'm facing a problem that my old javascript file no longer works properly
with constructions like instanceof, getClass(), throw.   Can someone point
me out how to do this?
 
try {
} catch (ex) {
    if (ex  instanceof Packages.xxxx.xxxx.xxxx) {
        //Do something 1
    } else if (ex.getClass().getName().equals("xxxx")) {
        //Do something 2
    }  else {
        //Do something 3
        throw(ex);
    }
}
 
Cheers,
Robby Pelssers


RE: how to catch and throw exceptions in cocoon2.1.10 (javascript)

Posted by "Robby Pelssers, AGP" <ro...@agp.nl>.
Hi Jason,

I tried out your proposal like below:

            try {
                if(name != null) {
                    this.wForm.lookupWidget("name").setValue(name)
                    this.version = CustomizableClassBinding.save(name,
this.wForm, this.version);
                }
            } catch (ex) {
            	print(ex.getWrappedException());
            }

It now gives me following error:
Message: TypeError: Cannot find function getWrappedException.
(file:/C:/osrdev/xenopsis/build/webapp/./xenopsis/content/portal/model/class
form.js#111)

Cheers,
Robby

-----Oorspronkelijk bericht-----
Van: Jason Johnston [mailto:cocoon@lojjic.net] 
Verzonden: woensdag 10 januari 2007 4:17
Aan: users@cocoon.apache.org
Onderwerp: Re: how to catch and throw exceptions in cocoon2.1.10
(javascript)

Robby Pelssers, AGP wrote:
> Hi,
>  
> I'm facing a problem that my old javascript file no longer works 
> properly with constructions like instanceof, getClass(), throw.   Can 
> someone point me out how to do this?
>  
> try {
> } catch (ex) {
>     if (ex  instanceof Packages.xxxx.xxxx.xxxx) {
>         //Do something 1
>     } else if (ex.getClass().getName().equals("xxxx")) {
>         //Do something 2
>     }  else {
>         //Do something 3
>         throw(ex);
>     }
> }


If I recall, the new version of Rhino treats exceptions from the Java layer
differently than it used to.  It used to pass them up to the JS catch
statement directly, whereas now it wraps them in a
org.mozilla.javascript.WrappedException.  You should be able to get access
to your original Java exception by unwrapping it with
ex.getWrappedException().

See 
http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/WrappedException
.html

--Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: how to catch and throw exceptions in cocoon2.1.10 (javascript)

Posted by Jason Johnston <co...@lojjic.net>.
Robby Pelssers, AGP wrote:
> Hi,
>  
> I'm facing a problem that my old javascript file no longer works 
> properly with constructions like instanceof, getClass(), throw.   Can 
> someone point me out how to do this?
>  
> try {
> } catch (ex) {
>     if (ex  instanceof Packages.xxxx.xxxx.xxxx) {
>         //Do something 1
>     } else if (ex.getClass().getName().equals("xxxx")) {
>         //Do something 2
>     }  else {
>         //Do something 3
>         throw(ex);
>     }
> }


If I recall, the new version of Rhino treats exceptions from the Java 
layer differently than it used to.  It used to pass them up to the JS 
catch statement directly, whereas now it wraps them in a 
org.mozilla.javascript.WrappedException.  You should be able to get 
access to your original Java exception by unwrapping it with 
ex.getWrappedException().

See 
http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/WrappedException.html

--Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org