Catch "Access Denied" exception?

95 views
Skip to first unread message

Nagisan

unread,
Sep 10, 2011, 11:12:45 AM9/10/11
to Cassia Users
How would you catch an exception in this example:

string host = "192.168.0.11;
using (ITerminalServer server =
_manager.GetRemoteServer(host))
{

server.Open();
foreach (ITerminalServicesSession session in
server.GetSessions())
{
if (session.UserAccount is object)
{
//random code
}
}
server.Close();
}

The primary issue is if the RPC server is down (can't connect) or
access is denied, it throws an error which ends the program....how
could I catch that to properly handle it how I want to handle it and
continue running the program?

Dan Ports

unread,
Sep 10, 2011, 5:48:01 PM9/10/11
to cassia...@googlegroups.com
server.Open() will throw if a connection to the remote server cannot be established.

Your best bet would be to put the entire code block in a try/catch, since even if the Open() call succeeds, other remote calls (server.GetSessions(), session.UserAccount) can fail if someone or something pulls the plug on the remote server after the call to Open().

Dan


--
You received this message because you are subscribed to the Google Groups "Cassia Users" group.
To post to this group, send email to cassia...@googlegroups.com.
To unsubscribe from this group, send email to cassia-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cassia-users?hl=en.


Nagisan

unread,
Sep 10, 2011, 5:57:01 PM9/10/11
to Cassia Users
Thanks.....I wasn't sure exactly how try-catch worked (done some c#
programming before, enough to be proficient enough to at least work
with it), didn't know it would catch any exception thrown in the try
block. Works great now though.

Dan Ports

unread,
Sep 10, 2011, 6:01:37 PM9/10/11
to cassia...@googlegroups.com
OK, great.
Reply all
Reply to author
Forward
0 new messages