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. General Programming
  3. C / C++ / MFC
  4. catch (...)

catch (...)

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 5 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.
  • B Offline
    B Offline
    Bill Wilson
    wrote on last edited by
    #1

    Does anyone know of a way to find out what was thrown in a "catch all" catch clause? The app I'm working on throws all sorts of things in addition to exceptions. I hate having to catch each one. e.g. throw TRUE; throw 3; throw ErrObject; Thanks for the help, Bill

    L G J 3 Replies Last reply
    0
    • B Bill Wilson

      Does anyone know of a way to find out what was thrown in a "catch all" catch clause? The app I'm working on throws all sorts of things in addition to exceptions. I hate having to catch each one. e.g. throw TRUE; throw 3; throw ErrObject; Thanks for the help, Bill

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

      You can't figure what is cought. That's the catch of catch(...) :-D

      1 Reply Last reply
      0
      • B Bill Wilson

        Does anyone know of a way to find out what was thrown in a "catch all" catch clause? The app I'm working on throws all sorts of things in addition to exceptions. I hate having to catch each one. e.g. throw TRUE; throw 3; throw ErrObject; Thanks for the help, Bill

        G Offline
        G Offline
        Ganesh Ramaswamy
        wrote on last edited by
        #3

        u can combine C++ error handling with C's SEH and u can use SEH to get information abt the exception. Please refer to John Robbins article on SEH and C++ in MSDN Magazine( i forgot the issue ) or his book Ganesh Ramaswamy

        1 Reply Last reply
        0
        • B Bill Wilson

          Does anyone know of a way to find out what was thrown in a "catch all" catch clause? The app I'm working on throws all sorts of things in addition to exceptions. I hate having to catch each one. e.g. throw TRUE; throw 3; throw ErrObject; Thanks for the help, Bill

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          There's no general way to catch anything throwable inside a try block. However, you can consider the possibility of having your app send an object of generic type, this meaning a class capable of holding values of an undetermined type. This beast indeed exists, and has been implemented in Boost any library (hey, it even works with MSVC++ 6.0). If you follow this approach, all you have to do is replace your throws with:

          throw bost::any(TRUE);
          throw boost::any(3);
          throw boost::any(ErrObject);

          Hope this helps. Joaquín M López Muñoz Telefónica, Ivnestigación y Desarrollo

          B 1 Reply Last reply
          0
          • J Joaquin M Lopez Munoz

            There's no general way to catch anything throwable inside a try block. However, you can consider the possibility of having your app send an object of generic type, this meaning a class capable of holding values of an undetermined type. This beast indeed exists, and has been implemented in Boost any library (hey, it even works with MSVC++ 6.0). If you follow this approach, all you have to do is replace your throws with:

            throw bost::any(TRUE);
            throw boost::any(3);
            throw boost::any(ErrObject);

            Hope this helps. Joaquín M López Muñoz Telefónica, Ivnestigación y Desarrollo

            B Offline
            B Offline
            Bill Wilson
            wrote on last edited by
            #5

            You're probably right about this being the way to go. I was hoping to avoid replacing several hundred assorted throw stmts that are already in the app. Oh well, Guess I'll get to work! :rolleyes: I appreaciate all the responses. Thanks for the help, Bill

            A 1 Reply Last reply
            0
            • B Bill Wilson

              You're probably right about this being the way to go. I was hoping to avoid replacing several hundred assorted throw stmts that are already in the app. Oh well, Guess I'll get to work! :rolleyes: I appreaciate all the responses. Thanks for the help, Bill

              A Offline
              A Offline
              Alvaro Mendez
              wrote on last edited by
              #6

              The easiest thing to do is to always throw exceptions using classes that derive from a single "exception" class, similar to how it works in Java. This allows you to always catch any of your exceptions using one

              catch(MyBaseException e)

              statement. I recommend using the std::exception class as your base class. Regards, Alvaro

              B 1 Reply Last reply
              0
              • A Alvaro Mendez

                The easiest thing to do is to always throw exceptions using classes that derive from a single "exception" class, similar to how it works in Java. This allows you to always catch any of your exceptions using one

                catch(MyBaseException e)

                statement. I recommend using the std::exception class as your base class. Regards, Alvaro

                B Offline
                B Offline
                Bill Wilson
                wrote on last edited by
                #7

                Thanks for the suggestion. I agree that this is the "best" solution. I was hoping to avoid replacing about 1300 throw's in the existing code base. Thanks for the help, Bill

                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