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.
  • 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