| |

VerySource

 Forgot password?
 Register
Search
View: 1595|Reply: 5

Some of the composite classes can be caught if an exception is thrown.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-11 00:20:01
| Show all posts |Read mode
Class TPart1
   {
      void __fastcall Function_1 (void)
      {
           const String Error_Str = "Error Of F1.";
           throw (Error_Str);
      }
    }

   Class TCombination
   {
        TCombination ();
        void __fastcall Act (void);
   }
  
   // * .h
   TPart1 * A_Part;

   TCombination :: TCombination ()
   {
        A_Part = new TPart1 ();
   }

   Combination :: Act (void)
   {
        try
        {
             A_Part-> Function_1 (); // After the program executes this sentence, it dies.
        }
        catch (...)
        {
                ShowMessage ("Errors Found.");
        }
    }

    // ??? why.
    // Post many times and it is not resolved, does anyone know?
    // Thank you.
Reply

Use magic Report

0

Threads

22

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-14 18:27:01
| Show all posts
What do you mean by dead?
Reply

Use magic Report

0

Threads

22

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-14 21:09:01
| Show all posts
The program removes case and function declaration errors ...
If it can be compiled, it is correct.
Reply

Use magic Report

0

Threads

18

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-24 18:00:02
| Show all posts
Help you
Reply

Use magic Report

0

Threads

13

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-7-12 18:00:01
| Show all posts
Tried your code, no problem
class TPart1
   {
   public:
void __fastcall Function_1( void)
{
const String Error_Str = "Error Of F1.";
throw (Error_Str );
}
};

   class TCombination
   {
   public:
TCombination( );
void __fastcall Act( void );
   };

   // *.h
   TPart1 *A_Part;

   TCombination::TCombination()
   {
A_Part = new TPart1( );
   }

   void __fastcall TCombination::Act( void)
   {
try
{
A_Part->Function_1( ); // After the program executes this sentence, it dies.
}
catch( ...)
{
ShowMessage( "Errors Found." );
}
}
int main(int argc, char* argv[])
{
TCombination c;
c.Act();
return 0;
}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-9-2 13:30:01
| Show all posts
There is a problem with my compiler. You can reinstall the system.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list