Thread ends while catching exception C#

48 views Asked by At

So I have a stack of calls. At the end of the stack an ArgumentException gets thrown. It propogates from to the last but one point where I have this code:

    ... Constructor(..){
        try
        {
            this.Issuer = issuer;
            this.Name = name;
            this.Secret = secret;
            this.totpObj = new Totp(secret, 30, 6, mode);
            this.id = Guid.NewGuid().ToString();
            this.mode = mode;
            this.valid = true;
        }
        catch (System.ArgumentException e)
        {
            throw e; // Also tried not having this --> option B

        }
        catch (Exception e)
        {

        }
    }

And this code gets called from here:

private void addButtnClick(object sender, RoutedEventArgs e)
   {
       try
       {
          ...
          TOTPObj totpo = new TOTPObj(af.Accname, af.Issuer, secret, stype); // <--- FAILS
          ...
       }
       catch(Exception ex) //  <--- SHOULD CATCH THIS?!
       {
           Console.WriteLine(ex);
           Environment.Exit(ERROR_FAILED_ADD_KEY);
       }
   }

Now if I leave the "throw" in the first section of code I get: enter image description here

While I think it should be caught at the next level? (second fragment of code).

If I don't throw the exception up but just do stuff there, I never get past the "<--- FAILS" point of code block two, the thread just exits. Why is that?

0

There are 0 answers