locked
catching the TRUE System.Web.Mail.Exception :) RRS feed

  • Question

  • User2028646954 posted
    Hello! :D try { SmtpMail.SmtpServer="mysmtpserverdude.com; SmtpMail.Send("me@mysmtpserverdude.com,"myself@ejii.com","hi","hello"); }catch(System.HttpException wrong) { Response.Write(wrong.Message) } well... looks good :D, but it aint do me no good :) if i put in a wrong emailadress and try to send it, the errormessage "Cant access CDO Message" will be displayed. But that is NOT the true error message. if i DONT use Try Catch and using Debug mode in VS. I get an error page saying System.Runtime.InteropServices.COMException "The mail receipents was rejected", THAT is the correct error message i want to catch. How do i do that?. I tried using the System.Runtime.InteropServices.COMException like this: }catch(System.Runtime.InteropServices.COMException wrong) { Response.Write(wrong.Message) } But it did me no good at all, it couldnt catch it at all :( .. soo.. i want to know how to catch the TRUE error :D
    Thursday, March 24, 2005 3:46 PM

All replies

  • User-368937792 posted

    A peek through reflector shows this:

    internal object CallMethod(object obj, string methodName, object[] args)
    {
          object obj1;
          try
          {
                obj1 = SmtpMail.LateBoundAccessHelper.CallMethod(this.LateBoundType, obj, methodName, args);
          }
          catch (Exception exception1)
          {
                throw new HttpException(HttpRuntime.FormatResourceString("Could_not_access_object", this._progId), exception1);
          }
          return obj1;
    }

    The HttpException is thrown with additional information over and above the COMException that is thrown by the actual call to CDO.

    If you want to read the COMException, try inspecting the InnerException property of the HttpException that was raised:

    try {
    SmtpMail.Send(myMessage);
    } catch (HttpException ex) {
    COMException comEx = ex.InnerException as COMException;
    if(comEx != null) {
    // COM error details
    }
    }
    Sunday, March 27, 2005 4:45 PM
  • User-444991860 posted
    In fact you can keep calling InnerException in this kind of way:
    catch ( exception ex )
    {
      while (ex != null)
      {
         Trace.Write(ex.Message);
         ex=ex.InnerException;
      }
    }
    That should get you the right exception eventually.
    Wednesday, March 30, 2005 3:52 AM