Registering custom exception classes

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Registering custom exception classes

Simon Bierbaum-2
Hi all,

I'm trying to send custom exceptions from Python to Flex (PyAMF 0.5.1, Flex 3.3). PyAMF 0.5 release notes suggest this is possible (http://blog.pyamf.org/archives/pyamf-0-5-released). However, I'm not exactly sure how I can accomplish this.

What I have is a custom Python exception, inheriting from exceptions.Exception:

class MyException(Exception):
def __init__(self, myAttribute=False):
self.myAttribute = myAttribute
pyamf.register_class(MyException, 'com.acme.MyException')

and in Flex, created a corresponding class:

package com.acme
{
[RemoteClass(alias="com.acme.MyException")]
[Bindable]
public class MyException extends Error
{
public var myAttribute:Boolean;


public function MyException() {


}
}
}

I have a Python method which I access via Flex' RemoteObject. Now whenever I raise a MyException in that method, Flex calls the registered FaultEvent handler, and the FaultEvent's "code" property is set to "MyException", but I cannot see myAttribute anywhere. Reading through pyamf.remoting.amf3's generate_error() function does not turn up anything either. 

Am I doing this right, or am I missing something? Any help is greatly appreciated.

Thanks,

Simon


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Registering custom exception classes

Thijs Triemstra
Hi Simon,

Have you tried pyamf.add_error_class [1] and pyamf.remove_error_class [2]? Might be >= 0.6 though..

hth,

Thijs


On 28 Jan 2010, at 16:11, Simon Bierbaum wrote:

Hi all,

I'm trying to send custom exceptions from Python to Flex (PyAMF 0.5.1, Flex 3.3). PyAMF 0.5 release notes suggest this is possible (http://blog.pyamf.org/archives/pyamf-0-5-released). However, I'm not exactly sure how I can accomplish this.

What I have is a custom Python exception, inheriting from exceptions.Exception:

class MyException(Exception):
def __init__(self, myAttribute=False):
self.myAttribute = myAttribute
pyamf.register_class(MyException, 'com.acme.MyException')

and in Flex, created a corresponding class:

package com.acme
{
[RemoteClass(alias="com.acme.MyException")]
[Bindable]
public class MyException extends Error
{
public var myAttribute:Boolean;

public function MyException() {

}
}
}

I have a Python method which I access via Flex' RemoteObject. Now whenever I raise a MyException in that method, Flex calls the registered FaultEvent handler, and the FaultEvent's "code" property is set to "MyException", but I cannot see myAttribute anywhere. Reading through pyamf.remoting.amf3's generate_error() function does not turn up anything either. 

Am I doing this right, or am I missing something? Any help is greatly appreciated.

Thanks,

Simon

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Registering custom exception classes

Simon Bierbaum-2
Hi Thijs,

add_error_class() is in 0.5.1 all right, but it only allows to map  
Python exceptions to custom faultCodes. I'd like to have an exception  
class with additional properties, mapped to a fully-fledged AS3  
class. Reading further, though, it seems like AMF and Flex' classes  
for error handling don't have a place for that, so I'm going to (mis-)
use either faultCode or faultDetail.

Thanks, Simon

Am 28.01.2010 um 19:15 schrieb Thijs Triemstra | Collab:

> Hi Simon,
>
> Have you tried pyamf.add_error_class [1] and  
> pyamf.remove_error_class [2]? Might be >= 0.6 though..
>
> hth,
>
> Thijs
>
> [1] http://dev.pyamf.org/browser/pyamf/trunk/pyamf/__init__.py#L1515
> [2] http://dev.pyamf.org/browser/pyamf/trunk/pyamf/__init__.py#L1549
>
> On 28 Jan 2010, at 16:11, Simon Bierbaum wrote:
>
>> Hi all,
>>
>> I'm trying to send custom exceptions from Python to Flex (PyAMF  
>> 0.5.1, Flex 3.3). PyAMF 0.5 release notes suggest this is possible  
>> (http://blog.pyamf.org/archives/pyamf-0-5-released). However, I'm  
>> not exactly sure how I can accomplish this.
>>
>> What I have is a custom Python exception, inheriting from  
>> exceptions.Exception:
>>
>> class MyException(Exception):
>> def __init__(self, myAttribute=False):
>> self.myAttribute = myAttribute
>> pyamf.register_class(MyException, 'com.acme.MyException')
>>
>> and in Flex, created a corresponding class:
>>
>> package com.acme
>> {
>> [RemoteClass(alias="com.acme.MyException")]
>> [Bindable]
>> public class MyException extends Error
>> {
>> public var myAttribute:Boolean;
>>
>> public function MyException() {
>>
>> }
>> }
>> }
>>
>> I have a Python method which I access via Flex' RemoteObject. Now  
>> whenever I raise a MyException in that method, Flex calls the  
>> registered FaultEvent handler, and the FaultEvent's "code"  
>> property is set to "MyException", but I cannot see myAttribute  
>> anywhere. Reading through pyamf.remoting.amf3's generate_error()  
>> function does not turn up anything either.
>>
>> Am I doing this right, or am I missing something? Any help is  
>> greatly appreciated.
>>
>> Thanks,
>>
>> Simon
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Registering custom exception classes

Nick Joyce
In reply to this post by Simon Bierbaum-2
If the gateway has debug=True, the `rootCause` object should contain the exception object (and therefore the myAttribute) ..
 
On 28 Jan 2010, at 10:11, Simon Bierbaum wrote:

Hi all,

I'm trying to send custom exceptions from Python to Flex (PyAMF 0.5.1, Flex 3.3). PyAMF 0.5 release notes suggest this is possible (http://blog.pyamf.org/archives/pyamf-0-5-released). However, I'm not exactly sure how I can accomplish this.

What I have is a custom Python exception, inheriting from exceptions.Exception:

class MyException(Exception):
def __init__(self, myAttribute=False):
self.myAttribute = myAttribute
pyamf.register_class(MyException, 'com.acme.MyException')

and in Flex, created a corresponding class:

package com.acme
{
[RemoteClass(alias="com.acme.MyException")]
[Bindable]
public class MyException extends Error
{
public var myAttribute:Boolean;

public function MyException() {

}
}
}

I have a Python method which I access via Flex' RemoteObject. Now whenever I raise a MyException in that method, Flex calls the registered FaultEvent handler, and the FaultEvent's "code" property is set to "MyException", but I cannot see myAttribute anywhere. Reading through pyamf.remoting.amf3's generate_error() function does not turn up anything either. 

Am I doing this right, or am I missing something? Any help is greatly appreciated.

Thanks,

Simon

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Registering custom exception classes

Simon Bierbaum-2
Nice, that's more neat than what I cooked up meanwhile. Thanks :-)  
Since I don't want to set debug to True (I want my Exception, but no  
stacktrace in the client), I monkey-patched  
pyamf.remoting.amf3.generate_error to set rootCause to the exception  
everytime.

Cheers, Simon

Am 29.01.2010 um 17:50 schrieb Nick Joyce:

> If the gateway has debug=True, the `rootCause` object should  
> contain the exception object (and therefore the myAttribute) ..
>
> On 28 Jan 2010, at 10:11, Simon Bierbaum wrote:
>
>> Hi all,
>>
>> I'm trying to send custom exceptions from Python to Flex (PyAMF  
>> 0.5.1, Flex 3.3). PyAMF 0.5 release notes suggest this is possible  
>> (http://blog.pyamf.org/archives/pyamf-0-5-released). However, I'm  
>> not exactly sure how I can accomplish this.
>>
>> What I have is a custom Python exception, inheriting from  
>> exceptions.Exception:
>>
>> class MyException(Exception):
>> def __init__(self, myAttribute=False):
>> self.myAttribute = myAttribute
>> pyamf.register_class(MyException, 'com.acme.MyException')
>>
>> and in Flex, created a corresponding class:
>>
>> package com.acme
>> {
>> [RemoteClass(alias="com.acme.MyException")]
>> [Bindable]
>> public class MyException extends Error
>> {
>> public var myAttribute:Boolean;
>>
>> public function MyException() {
>>
>> }
>> }
>> }
>>
>> I have a Python method which I access via Flex' RemoteObject. Now  
>> whenever I raise a MyException in that method, Flex calls the  
>> registered FaultEvent handler, and the FaultEvent's "code"  
>> property is set to "MyException", but I cannot see myAttribute  
>> anywhere. Reading through pyamf.remoting.amf3's generate_error()  
>> function does not turn up anything either.
>>
>> Am I doing this right, or am I missing something? Any help is  
>> greatly appreciated.
>>
>> Thanks,
>>
>> Simon
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Registering custom exception classes

Nick Joyce
That sounds more sensible than the way it happens currently ..

I'll add a ticket for the change.

Cheers,

Nick

On 29 Jan 2010, at 11:04, Simon Bierbaum wrote:

> Nice, that's more neat than what I cooked up meanwhile. Thanks :-) Since I don't want to set debug to True (I want my Exception, but no stacktrace in the client), I monkey-patched pyamf.remoting.amf3.generate_error to set rootCause to the exception everytime.
>
> Cheers, Simon
>
> Am 29.01.2010 um 17:50 schrieb Nick Joyce:
>
>> If the gateway has debug=True, the `rootCause` object should contain the exception object (and therefore the myAttribute) ..
>>
>> On 28 Jan 2010, at 10:11, Simon Bierbaum wrote:
>>
>>> Hi all,
>>>
>>> I'm trying to send custom exceptions from Python to Flex (PyAMF 0.5.1, Flex 3.3). PyAMF 0.5 release notes suggest this is possible (http://blog.pyamf.org/archives/pyamf-0-5-released). However, I'm not exactly sure how I can accomplish this.
>>>
>>> What I have is a custom Python exception, inheriting from exceptions.Exception:
>>>
>>> class MyException(Exception):
>>> def __init__(self, myAttribute=False):
>>> self.myAttribute = myAttribute
>>> pyamf.register_class(MyException, 'com.acme.MyException')
>>>
>>> and in Flex, created a corresponding class:
>>>
>>> package com.acme
>>> {
>>> [RemoteClass(alias="com.acme.MyException")]
>>> [Bindable]
>>> public class MyException extends Error
>>> {
>>> public var myAttribute:Boolean;
>>>
>>> public function MyException() {
>>>
>>> }
>>> }
>>> }
>>>
>>> I have a Python method which I access via Flex' RemoteObject. Now whenever I raise a MyException in that method, Flex calls the registered FaultEvent handler, and the FaultEvent's "code" property is set to "MyException", but I cannot see myAttribute anywhere. Reading through pyamf.remoting.amf3's generate_error() function does not turn up anything either.
>>>
>>> Am I doing this right, or am I missing something? Any help is greatly appreciated.
>>>
>>> Thanks,
>>>
>>> Simon
>>>
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users