Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try/Catch doesn't catch exception

Tags:

c#

.net

fiddler

I have project with FiddlerApplication that saves some sessions for me. When I start the program first launch after restart 100% fails and then 10% fails 90% works.

The biggest problem that when it fails it doesn't catch any exceptions in try/catch. Here is my code

static class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        try
        {
            browserToRun.GoTo("www.test.com"); 
            FiddlerApplication.AfterSessionComplete +=  FiddlerApplication_AfterSessionComplete;

            //HERE it fails
            FiddlerApplication.Startup(8888, true, true, true);
            FiddlerApplication.Shutdown();
        }
        catch (Exception ex)
        {
            // it is not getting to here
            FiddlerApplication.AfterSessionComplete -= FiddlerApplication_AfterSessionComplete;
            FiddlerApplication.Shutdown();
        }
    }

    public static void FiddlerApplication_AfterSessionComplete(Session sess)
    {
        try
        {
            if (!sess.fullUrl.Contains("test"))
            return;
            GlobalDownloadLink = sess.fullUrl;
        }
        catch (Exception ex)
        {
            successful = false;

            throw new System.ArgumentException(ex.Message, "FiddlerApplication_AfterSessionComplete");
        }
    }
}

My new Updated Apconfigwith new error Configuration System Failed to Initialize

<configuration>

  <runtime>
    <legacyCorruptedStateExceptionsPolicy enabled="true" />
  </runtime>
<configSections>

</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

  <appSettings>
    <add key="BrowserShow" value="Y"/>
    <add key="DebugCreate" value="true"/>
    <add key="FileName10" value="AccountActivity"/>
    <add key="FileName20" value="ForeignActivities"/>
    <add key="FileNameShar" value="MatbeotSchirim"/>
  </appSettings>
</configuration>
like image 431
Vladimir Potapov Avatar asked May 28 '15 06:05

Vladimir Potapov


2 Answers

Some Exceptions are not getting caught by try..catch blocks unless you specify the attribute [HandleProcessCorruptedStateExceptions] on the function (Main function in your code). Of couse, the same could be accomplished by modifying the config file as Oxoron described.

like image 139
Peter Brennan Avatar answered Sep 21 '22 12:09

Peter Brennan


Try to add <runtime> <legacyCorruptedStateExceptionsPolicy enabled="true" /> </runtime>

to the config file. Source here.

like image 44
Oxoron Avatar answered Sep 25 '22 12:09

Oxoron