how to catch/handle the inner rasdialer exception

Sep 13, 2011 at 10:25 AM

Howdie,

Maybe a noob question , but I am trying to get the inner exception mesage... when an error occured dialing a VPN connection:

In my DialerCompleted event I see the error occured....  but cannot get to the inner excetion stuff.

    private void buddyDialer_DialCompleted(object sender, DialCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                  // e.Error = {"Exception of type 'DotRas.RasDialException' was thrown."}
}}
I tried the to catch the error during the dial process , but does not work ( Note - I also also tried to catch all exceptions...)
try
                        {
                            this.buddyDialer.DialAsync();
                        }
                   
                        catch (DotRas.RasException re)
                        {
                            if (re.ErrorCode == 756) // already dialed connection
                            {
                                helperSetConnectedStatus();
                            }
                        }
     
I also subscribed to the RasDialer Error event, but it does not break into it whilst debugging...
any ideas ? (thx)
Coordinator
Sep 14, 2011 at 3:17 AM

The error property on DialCompletedEventArgs contains the error that was raised during an asynchronous dial attempt. Unless something majorly goes wrong the DialAsync method on RasDialer will still allow the DialCompleted event to be raised with the error that occurred inside that property. There are however circumstances where exceptions are thrown before a connection gets into a state that could raise the DialCompleted event. Since the errors inside this aren't actually thrown, you can't catch them. As for the exception message being "Exception of type 'DotRas.RasDialException" more than likely the error code on the exception isn't one of the RAS error codes, which would mean an empty string would come back during translation and the default message (what your seeing) is shown instead. There typically is no inner exception data in the Error property of DialCompletedEventArgs because errors that occur here are inside native code and aren't something that can be caught.

The Error event on the component is there because there's a try block around all pieces of the component that raise events in case an exception is thrown by user code which is outside the control of the component. For example, the component raises an event and a developer that's using the component throws a divide by zero exception. That exception would get caught and bubbled up through the Error event on RasDialer. This prevents unhandled exceptions in user code breaking the component during a callback that could corrupt the RAS state machine and require the machine to be rebooted to clear the problem.

Sep 19, 2011 at 4:06 PM

Thx for answering  Jeff.  I  dig around in DialCompletedEventArg  and manage to get an error code out of it : ((DotRas.RasDialException)e.Error).ErrorCode