RE: [Mono-list] Using Exceptions with external Plugins

2004-06-29 Thread Arild Fines
[EMAIL PROTECTED] wrote:
 Cool! Thanks!

 Now, how can I get sure that the InnerException is a
 XmlRpcFaultException or a XmlRpcMissedSomething?, I'm trying with this:

 } catch(TargetInvocationException e) {
if(e.InnerException.GetType().ToString() ==
 CookComputing.XmlRpc.XmlRpcFaultException) {
Console.WriteLine(yes);
 }

 But I don't think it's the correct way/code, any suggestions?

You might want to take advantage of the fact that Type.InvokeMember actually
performs virtual dispatch based on the runtime type of the object *AND* all
of the parameters, IE, it performs double/triple/ntuple dispatch.

That means the following will work the way you want it to:

catch( TargetInvocationException e )
{
Type t = this.GetType();
t.InvokeMember( HandleException, BindingFlags.InvokeMethod |
BindingFlags.Instance | BindingFlags.NonPublic, null,
this, new object[]{ e } );
}

// ...

private void HandleException( CookComputing.XmlRpc.XmlRpcFaultException e )
{
   //...
}

private void HandleException( FooException e )
{
   //...
}

private void HandleException( Exception e )
{
   // called if there are no other matching signatures
}

Of course, it isn't particularly fast...

--
Arild

AnkhSVN: http://ankhsvn.tigris.org
Blog: http://ankhsvn.com/blog
IRC: irc://irc.freenode.net/ankhsvn

Weaseling out of things is good. It's what separates us from the other
animalsexcept weasels. -- Homer Simpson

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


RE: [Mono-list] Using Exceptions with external Plugins

2004-06-29 Thread Pablo Fischer
Thanks!

However, I think the best idea is to use generic Exceptions, if I try to
use the CookComputing.XmlRpc Exceptions I need to compile ALL my
application with CookComputing.dll and I'm not looking that, that's why
I'm working with plugins to just compile CookComputing.XmlRpc in the
plugins and not in all the application.

Thanks for these suggestions!
Pablo


El mar, 29-06-2004 a las 09:06, Arild Fines escribió:
 [EMAIL PROTECTED] wrote:
  Cool! Thanks!
 
  Now, how can I get sure that the InnerException is a
  XmlRpcFaultException or a XmlRpcMissedSomething?, I'm trying with this:
 
  } catch(TargetInvocationException e) {
 if(e.InnerException.GetType().ToString() ==
  CookComputing.XmlRpc.XmlRpcFaultException) {
 Console.WriteLine(yes);
  }
 
  But I don't think it's the correct way/code, any suggestions?
 
 You might want to take advantage of the fact that Type.InvokeMember actually
 performs virtual dispatch based on the runtime type of the object *AND* all
 of the parameters, IE, it performs double/triple/ntuple dispatch.
 
 That means the following will work the way you want it to:
 
 catch( TargetInvocationException e )
 {
   Type t = this.GetType();
   t.InvokeMember( HandleException, BindingFlags.InvokeMethod |
   BindingFlags.Instance | BindingFlags.NonPublic, null,
 this, new object[]{ e } );
 }
 
 // ...
 
 private void HandleException( CookComputing.XmlRpc.XmlRpcFaultException e )
 {
//...
 }
 
 private void HandleException( FooException e )
 {
//...
 }
 
 private void HandleException( Exception e )
 {
// called if there are no other matching signatures
 }
 
 Of course, it isn't particularly fast...
 
 --
 Arild
 
 AnkhSVN: http://ankhsvn.tigris.org
 Blog: http://ankhsvn.com/blog
 IRC: irc://irc.freenode.net/ankhsvn
 
 Weaseling out of things is good. It's what separates us from the other
 animalsexcept weasels. -- Homer Simpson
-- 
Pablo Fischer Sandoval (pablo [arroba/at] pablo.com.mx)
Fingerprint:  5973 0F10 543F 54AE 1E41  EC81 0840 A10A 74A4 E5C0
http://www.pablo.com.mx 
http://www.debianmexico.org


signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada	digitalmente


RE: [Mono-list] Using Exceptions with external Plugins

2004-06-28 Thread Arild Fines
[EMAIL PROTECTED] wrote:
 Hi!

 I'm loading many plugins (assemblies, dll) from my App.exe, however
 sometimes a plugin can throw an exception, how can I catch it?, I can
 only catch the System.Reflection.TargetInvocationException cause I'm
 using Reflection/Invoke techniques.. but I can't 'catch' 'internal
 Exceptions' of these plugins.

 For example, a Plugin.dll can throw a
 CookComputing.XmlRpc.XmlRpcFaultException and it doesn't works, however
 System.Reflection.TargetInvocationException seems to catch it, but just
 the Invoke Exception.

 Any ideas?
 Pablo

The docs on TargetInvocationException has this:

When created, the TargetInvocationException is passed a reference to the
exception thrown by the method invoked through reflection. The
InnerException property holds the underlying exception.

So tex.InnerException should give you what you need.

--
Arild

AnkhSVN: http://ankhsvn.tigris.org
Blog: http://ankhsvn.com/blog
IRC: irc://irc.freenode.net/ankhsvn

Weaseling out of things is good. It's what separates us from the other
animalsexcept weasels. -- Homer Simpson

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


RE: [Mono-list] Using Exceptions with external Plugins

2004-06-28 Thread Pablo Fischer
Cool! Thanks!

Now, how can I get sure that the InnerException is a
XmlRpcFaultException or a XmlRpcMissedSomething?, I'm trying with this:

} catch(TargetInvocationException e) {
   if(e.InnerException.GetType().ToString() ==   
CookComputing.XmlRpc.XmlRpcFaultException) {
   Console.WriteLine(yes);
}

But I don't think it's the correct way/code, any suggestions?

Thanks!
Pablo

El lun, 28-06-2004 a las 18:54, Arild Fines escribió:
 [EMAIL PROTECTED] wrote:
  Hi!
 
  I'm loading many plugins (assemblies, dll) from my App.exe, however
  sometimes a plugin can throw an exception, how can I catch it?, I can
  only catch the System.Reflection.TargetInvocationException cause I'm
  using Reflection/Invoke techniques.. but I can't 'catch' 'internal
  Exceptions' of these plugins.
 
  For example, a Plugin.dll can throw a
  CookComputing.XmlRpc.XmlRpcFaultException and it doesn't works, however
  System.Reflection.TargetInvocationException seems to catch it, but just
  the Invoke Exception.
 
  Any ideas?
  Pablo
 
 The docs on TargetInvocationException has this:
 
 When created, the TargetInvocationException is passed a reference to the
 exception thrown by the method invoked through reflection. The
 InnerException property holds the underlying exception.
 
 So tex.InnerException should give you what you need.
 
 --
 Arild
 
 AnkhSVN: http://ankhsvn.tigris.org
 Blog: http://ankhsvn.com/blog
 IRC: irc://irc.freenode.net/ankhsvn
 
 Weaseling out of things is good. It's what separates us from the other
 animalsexcept weasels. -- Homer Simpson
 
 ___
 Mono-list maillist  -  [EMAIL PROTECTED]
 http://lists.ximian.com/mailman/listinfo/mono-list
-- 
Pablo Fischer Sandoval (pablo [arroba/at] pablo.com.mx)
Fingerprint:  5973 0F10 543F 54AE 1E41  EC81 0840 A10A 74A4 E5C0
http://www.pablo.com.mx 
http://www.debianmexico.org


signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada	digitalmente


RE: [Mono-list] Using Exceptions with external Plugins

2004-06-28 Thread Iain McCoy
On Tue, 2004-06-29 at 11:14, Pablo Fischer wrote:
 Cool! Thanks!
 
 Now, how can I get sure that the InnerException is a
 XmlRpcFaultException or a XmlRpcMissedSomething?, I'm trying with this:
 
 } catch(TargetInvocationException e) {
if(e.InnerException.GetType().ToString() ==   
 CookComputing.XmlRpc.XmlRpcFaultException) {
Console.WriteLine(yes);
else 
 }
 
 But I don't think it's the correct way/code, any suggestions?
You might try this:
if(e.InnerException is CookComputing.XmlRpc.XmlRpcFaultException)

You should also do something sensible with exceptions that fail all your
if statements. That might be rethrowing or some sort of generic error
message.
-- 
Iain McCoy [EMAIL PROTECTED]

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list