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. Clever Code
  4. C# rots your C++ brain part 2

C# rots your C++ brain part 2

Scheduled Pinned Locked Moved Clever Code
csharpc++question
22 Posts 15 Posters 88 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.
  • J Jorgen Sigvardsson

    class MyException : std::exception {
    ...
    }

    try {
    throw MyException();
    } catch(std::exception& ex) {
    }

    The exception is not going to be caught. Can you figure out why?

    A Offline
    A Offline
    Al Beback
    wrote on last edited by
    #21

    I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of: throw MyException**()**; In C++, you don't use parenthesis when instanciating an object with the default constructor (ie, throw MyException;). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?

    ShamWow

    J 1 Reply Last reply
    0
    • A Al Beback

      I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of: throw MyException**()**; In C++, you don't use parenthesis when instanciating an object with the default constructor (ie, throw MyException;). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?

      ShamWow

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #22

      It does not matter if you use the parenthesis or not, the default constructor is called anyway. I tend to use parenthesis (how the hell do you pluralize that word? :)), because it makes the syntax more uniform. There are some odd scenarios though, where the parenthesis can fool the compiler into believing that you're declaring a function prototype. Can't remember exactly how to provoke it though...

      -- Kein Mitleid Für Die Mehrheit

      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