Results 1 to 3 of 3

Thread: [2.0] Catching Exceptions Thrown via Remoting

  1. #1

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Arrow [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

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    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
    }

  3. #3

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width