Why do i get uncaught exception and the program exits?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hype261
    New Member
    • Apr 2010
    • 207

    #16
    If I had to make a guess on why exceptions don't support implicit conversions is because it would be very difficult to do.

    Implicit conversions for functions are realitively easy thing for a compiler to do. This function needs a Class A, but you gave it Class B, but A can be constructed from B. Now consider the following code example.

    Code:
    class Error
    {
    public:
         Error(string c){cout << c;};
    };
    
    void c()
    {
         throw string("HELP");
    }
    
    void b()
    {
         c();
    }
    
    void a()
    {
         b();
    }
    
    int main()
    {
         try
         {
              a();
         }
         catch(Error err)
         {
         }
    }
    In this situation the compilier is going to have to go three functions deep to see you are going to throw a string and then do the implicit conversion. This example is really simple, consider what would happen if this was a real application. The compiler could be 50 functions deep across multiple source files.

    Comment

    Working...