|
-
Aug 5th, 2007, 09:57 PM
#1
[2.0] Catching Exceptions Thrown via Remoting
Hi all,
I have a MarshalByRefObject which lives on a server and is accessed via a proxy created by Activator.GetObject(). This all works.
I would like to be able to throw an exception in a server-side method and catch it on the client-side.
Is this possible at all? If so, how would I go about doing that? So far when I've tried, I've either had no exception pop up at all, or an "uncaught exception" error on the server-side.
Cheers
- P
-
Aug 6th, 2007, 11:27 AM
#2
Re: [2.0] Catching Exceptions Thrown via Remoting
Here's how I handle remoting, and the exception thrown in the ProcessFile method gets caught by the calling program.
Code:
try
{
System.Runtime.Remoting.ObjectHandle handle =
Activator.CreateInstanceFrom("assemblyFile","typeName");
IFileProcessor processor = handle.Unwrap();
processor.ProcessFile("",null);
}
catch (System.Exception ex)
{
//handle exception
}
-
Aug 22nd, 2007, 12:05 AM
#3
Re: [2.0] Catching Exceptions Thrown via Remoting
I'm still having problems with this.
Here's some code.
Client:
Code:
try
{
this.serverObj.ExceptionTest();
}
catch (Exception ex)
{
return ex.Message;
}
return null;
Server:
Code:
[Serializable]
public class ServerException : Exception, ISerializable
{
public ServerException(string msg)
: base(msg) { }
public ServerException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
// ......
/// <summary>
/// Simulate an error condition
/// </summary>
public void ExceptionTest()
{
throw new ServerException("Simulated Exception");
}
When I call ExceptionTest from the client, I get an error "ServerException was unhandled by user code" on the server on the throw line in ExceptionTest.
I would have thought that, being marked Serializable, the exception could be propagated across the remoting boundary.
What's the fundamental thing that I'm missing here?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|