Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. // Do not remove this try catch block.

// Do not remove this try catch block.

Scheduled Pinned Locked Moved The Weird and The Wonderful
questioncomhelptutorial
22 Posts 14 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Oh go on, you know you want to.. :laugh:

    try
    {
    Filtering = !filters.IsEmpty;
    }
    catch(Exception ex)
    {
    Filtering = !filters.IsEmpty;
    }
    finally
    {
    Filtering = !filters.IsEmpty;
    }

    Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.

    R Offline
    R Offline
    raddevus
    wrote on last edited by
    #3

    I want my filters to be NON-EMPTY!!!! I'll get my filters to be NON-EMPTY!!! :| :laugh: And why not just? :

    Filtering = true;

    If it throwing an exception on that, then maybe it is the Filtering var that is undefined?

    L 1 Reply Last reply
    0
    • R raddevus

      I want my filters to be NON-EMPTY!!!! I'll get my filters to be NON-EMPTY!!! :| :laugh: And why not just? :

      Filtering = true;

      If it throwing an exception on that, then maybe it is the Filtering var that is undefined?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      Hammer. Bigger Hammer. Biggest Hammer. :laugh:

      Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.

      1 Reply Last reply
      0
      • Y Yusuf

        try
        {
        Filtering = !filters.IsEmpty;
        }
        catch(Exception ex)
        {
        // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
        }
        finally
        {
        Filtering = !filters.IsEmpty;
        }

        Oh My eyes :wtf:

        Yusuf May I help you?

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #5

        At least make it catch only null reference exceptions? And let Bob sort out the rest?

        1 Reply Last reply
        0
        • Y Yusuf

          try
          {
          Filtering = !filters.IsEmpty;
          }
          catch(Exception ex)
          {
          // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
          }
          finally
          {
          Filtering = !filters.IsEmpty;
          }

          Oh My eyes :wtf:

          Yusuf May I help you?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #6

          Hmmm, I can infer from this snippet that the filters variable is most likely a CString[^] member variable which is being modified/accessed by multiple threads. Am I right? :) Best Wishes, -David Delaune

          Y 1 Reply Last reply
          0
          • Y Yusuf

            try
            {
            Filtering = !filters.IsEmpty;
            }
            catch(Exception ex)
            {
            // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
            }
            finally
            {
            Filtering = !filters.IsEmpty;
            }

            Oh My eyes :wtf:

            Yusuf May I help you?

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #7

            I am trying to figure out how that can work. What about

            private Something _filters;
            private Something filters
            {
            get
            {
            if (_filters == null)
            {
            Task.Run(() => CreateFilters());
            }
            return _filters;
            }
            }
            private void CreateFilters()
            {
            // somehow instantiates a Something and sets the _filters member
            }

            That could cause such a strange behavior, couldn't it? :-D

            P Y 2 Replies Last reply
            0
            • Y Yusuf

              try
              {
              Filtering = !filters.IsEmpty;
              }
              catch(Exception ex)
              {
              // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
              }
              finally
              {
              Filtering = !filters.IsEmpty;
              }

              Oh My eyes :wtf:

              Yusuf May I help you?

              K Offline
              K Offline
              KBZX5000
              wrote on last edited by
              #8

              Just remove the try-catch and stack-trace the exception. I don't see the problem. o7

              1 Reply Last reply
              0
              • B Bernhard Hiller

                I am trying to figure out how that can work. What about

                private Something _filters;
                private Something filters
                {
                get
                {
                if (_filters == null)
                {
                Task.Run(() => CreateFilters());
                }
                return _filters;
                }
                }
                private void CreateFilters()
                {
                // somehow instantiates a Something and sets the _filters member
                }

                That could cause such a strange behavior, couldn't it? :-D

                P Offline
                P Offline
                Plamen Dragiyski
                wrote on last edited by
                #9

                I think he might not know what Multi-Threaded Programming is.

                B 1 Reply Last reply
                0
                • Y Yusuf

                  try
                  {
                  Filtering = !filters.IsEmpty;
                  }
                  catch(Exception ex)
                  {
                  // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
                  }
                  finally
                  {
                  Filtering = !filters.IsEmpty;
                  }

                  Oh My eyes :wtf:

                  Yusuf May I help you?

                  M Offline
                  M Offline
                  maze3
                  wrote on last edited by
                  #10

                  OMG that is terrible

                  try {
                  Filtering = !filters.IsEmpty;
                  }
                  catch(Exception ex) {
                  // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
                  }
                  finally {
                  Filtering = !filters.IsEmpty;
                  }

                  1 Reply Last reply
                  0
                  • Y Yusuf

                    try
                    {
                    Filtering = !filters.IsEmpty;
                    }
                    catch(Exception ex)
                    {
                    // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
                    }
                    finally
                    {
                    Filtering = !filters.IsEmpty;
                    }

                    Oh My eyes :wtf:

                    Yusuf May I help you?

                    K Offline
                    K Offline
                    kristopher baker
                    wrote on last edited by
                    #11

                    My guess is that either "filters" isn't instantiated or is getting instantiated at the same time that it is being called. What is happening when "IsEmpty" is called? It might be trying to kick something off when it is called.

                    M 1 Reply Last reply
                    0
                    • K kristopher baker

                      My guess is that either "filters" isn't instantiated or is getting instantiated at the same time that it is being called. What is happening when "IsEmpty" is called? It might be trying to kick something off when it is called.

                      M Offline
                      M Offline
                      Middle Manager
                      wrote on last edited by
                      #12

                      I second that request. Can we be shown the IsEmpty code please? Can't be too many company secrets hidden in there... god, please say there isn't! :omg:

                      U Y 2 Replies Last reply
                      0
                      • Y Yusuf

                        try
                        {
                        Filtering = !filters.IsEmpty;
                        }
                        catch(Exception ex)
                        {
                        // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
                        }
                        finally
                        {
                        Filtering = !filters.IsEmpty;
                        }

                        Oh My eyes :wtf:

                        Yusuf May I help you?

                        A Offline
                        A Offline
                        agolddog
                        wrote on last edited by
                        #13

                        Outside of that... Who knows the context, but I'm going to guess that filters is a private member property, and Filtering is exposed. Why wouldn't someone just make Filtering a public, get-only convenience property then, rather than setting some piece of data, where we now have to maintain two things?

                        1 Reply Last reply
                        0
                        • P Plamen Dragiyski

                          I think he might not know what Multi-Threaded Programming is.

                          B Offline
                          B Offline
                          Bernhard Hiller
                          wrote on last edited by
                          #14

                          Exactly. But somewhere he read something about lazy initialization, and somewhere else he saw a Task.Run, understood neither of them, and ... Welcome to the wonderful world of code monkeys who've used every programming concept during their career. :^)

                          1 Reply Last reply
                          0
                          • M Middle Manager

                            I second that request. Can we be shown the IsEmpty code please? Can't be too many company secrets hidden in there... god, please say there isn't! :omg:

                            U Offline
                            U Offline
                            User 11277767
                            wrote on last edited by
                            #15

                            public bool IsEmpty
                            {
                            get {
                            try {
                            return _filters.IsEmpty();
                            }
                            catch (NullReferenceException e)
                            {
                            InstantiateFilters();
                            throw new NullReferenceException("Try it again now please.");
                            }
                            }
                            }

                            K 1 Reply Last reply
                            0
                            • Y Yusuf

                              try
                              {
                              Filtering = !filters.IsEmpty;
                              }
                              catch(Exception ex)
                              {
                              // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
                              }
                              finally
                              {
                              Filtering = !filters.IsEmpty;
                              }

                              Oh My eyes :wtf:

                              Yusuf May I help you?

                              D Offline
                              D Offline
                              Daniel R Przybylski
                              wrote on last edited by
                              #16

                              Are You A Code Poet? - I'm silently reviewing your code T-Shirt | Teespring[^]

                              1 Reply Last reply
                              0
                              • Y Yusuf

                                try
                                {
                                Filtering = !filters.IsEmpty;
                                }
                                catch(Exception ex)
                                {
                                // Do not remove this try catch block. For some reason this always throws Null reference exception but then works.
                                }
                                finally
                                {
                                Filtering = !filters.IsEmpty;
                                }

                                Oh My eyes :wtf:

                                Yusuf May I help you?

                                L Offline
                                L Offline
                                Leng Vang
                                wrote on last edited by
                                #17

                                Zombie coder?

                                1 Reply Last reply
                                0
                                • L Lost User

                                  Hmmm, I can infer from this snippet that the filters variable is most likely a CString[^] member variable which is being modified/accessed by multiple threads. Am I right? :) Best Wishes, -David Delaune

                                  Y Offline
                                  Y Offline
                                  Yusuf
                                  wrote on last edited by
                                  #18

                                  Nope. filter is ICollectionView [^](https://msdn.microsoft.com/en-us/library/system.componentmodel.icollectionview(v=vs.110).aspx) type. It is possible it could be null.

                                  Yusuf May I help you?

                                  1 Reply Last reply
                                  0
                                  • B Bernhard Hiller

                                    I am trying to figure out how that can work. What about

                                    private Something _filters;
                                    private Something filters
                                    {
                                    get
                                    {
                                    if (_filters == null)
                                    {
                                    Task.Run(() => CreateFilters());
                                    }
                                    return _filters;
                                    }
                                    }
                                    private void CreateFilters()
                                    {
                                    // somehow instantiates a Something and sets the _filters member
                                    }

                                    That could cause such a strange behavior, couldn't it? :-D

                                    Y Offline
                                    Y Offline
                                    Yusuf
                                    wrote on last edited by
                                    #19

                                    var filters = Grid.RecordManager.FilteredInDataItems;

                                    it is using 3rd party grid control. It returns ICollectionView [^](https://msdn.microsoft.com/en-us/library/system.componentmodel.icollectionview(v=vs.110).aspx)

                                    Yusuf May I help you?

                                    1 Reply Last reply
                                    0
                                    • M Middle Manager

                                      I second that request. Can we be shown the IsEmpty code please? Can't be too many company secrets hidden in there... god, please say there isn't! :omg:

                                      Y Offline
                                      Y Offline
                                      Yusuf
                                      wrote on last edited by
                                      #20

                                      bool IsEmpty { get; }

                                      Member of System.ComponentModel.ICollectionView

                                      Yusuf May I help you?

                                      1 Reply Last reply
                                      0
                                      • U User 11277767

                                        public bool IsEmpty
                                        {
                                        get {
                                        try {
                                        return _filters.IsEmpty();
                                        }
                                        catch (NullReferenceException e)
                                        {
                                        InstantiateFilters();
                                        throw new NullReferenceException("Try it again now please.");
                                        }
                                        }
                                        }

                                        K Offline
                                        K Offline
                                        kristopher baker
                                        wrote on last edited by
                                        #21

                                        That tells you everything. You're variously trying to call an IsEmpty() method on a null _filters object. The exception is caught, InstantiateFilters() then fills up your filters variable from your calling code. The next time around in the finally it calls on the IsEmpty property again but this time _filters has been instantiated and the 'try' passes without a problem.

                                        U 1 Reply Last reply
                                        0
                                        • K kristopher baker

                                          That tells you everything. You're variously trying to call an IsEmpty() method on a null _filters object. The exception is caught, InstantiateFilters() then fills up your filters variable from your calling code. The next time around in the finally it calls on the IsEmpty property again but this time _filters has been instantiated and the 'try' passes without a problem.

                                          U Offline
                                          U Offline
                                          User 11277767
                                          wrote on last edited by
                                          #22

                                          I'm not the OP so I have no knowledge of the actual code. That was just a stupid joke on my part.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups