1
// Copyright 2006 Alp Toker <alp@atoker.com>
2
// This software is made available under the MIT License
3
// See COPYING for details
6
using System.Collections.Generic;
8
using org.freedesktop.DBus;
10
public class ManagedDBusTestExceptions
12
public static void Main ()
14
Bus bus = Bus.Session;
16
string myNameReq = "org.ndesk.testexceptions";
17
ObjectPath myOpath = new ObjectPath ("/org/ndesk/testexceptions");
21
if (bus.NameHasOwner (myNameReq)) {
22
demo = bus.GetObject<DemoObject> (myNameReq, myOpath);
24
demo = new DemoObject ();
25
bus.Register (myNameReq, myOpath, demo);
27
RequestNameReply nameReply = bus.RequestName (myNameReq, NameFlag.None);
28
Console.WriteLine ("RequestNameReply: " + nameReply);
35
//org.freedesktop.DBus.Error.InvalidArgs: Requested bus name "" is not valid
38
} catch (Exception e) {
39
Console.WriteLine (e);
42
//TODO: make this work as expected (what is expected?)
45
demo.ThrowSomeException ();
46
} catch (Exception e) {
47
Console.WriteLine (e);
52
demo.ThrowSomeExceptionNoRet ();
53
} catch (Exception e) {
54
Console.WriteLine (e);
56
//handle the thrown exception
61
demo.HandleVariant (null);
62
} catch (Exception e) {
63
Console.WriteLine (e);
68
demo.HandleString (null);
69
} catch (Exception e) {
70
Console.WriteLine (e);
75
demo.HandleArray (null);
76
} catch (Exception e) {
77
Console.WriteLine (e);
82
[Interface ("org.ndesk.testexceptions")]
83
public class DemoObject : MarshalByRefObject
85
public int ThrowSomeException ()
87
Console.WriteLine ("Asked to throw some Exception");
89
throw new Exception ("Some Exception");
92
public void ThrowSomeExceptionNoRet ()
94
Console.WriteLine ("Asked to throw some Exception NoRet");
96
throw new Exception ("Some Exception NoRet");
99
public void HandleVariant (object o)
101
Console.WriteLine (o);
104
public void HandleString (string str)
106
Console.WriteLine (str);
109
public void HandleArray (byte[] arr)
111
Console.WriteLine (arr);