Some about abnormalities

xiaoxiao2021-03-06  42

Implementation:

1. Defining an exception (TRY sentence block) That's in the TRY block of statements that may generate errors

2. Define exception handling (Catch statement block) placing an exception handle in the CATCH block so that it is processed when it is passed.

3. Throwing anomaly (THROW statement) detects whether it produces an abnormality, if so, throw an exception

Such as: The following procedure sets the exception of the guard file.

#include #include #include

Void Main (int Argc, char * * argv) {ifstream Source (argv [1]); //? ò ?????? char line [128]; try {if (Source.Fail ()) throw argv [ 1]; }

Catch (char * s) {cout << "error opening the file" << s << endl; exit (1);

While (! source.eof ()) {source.getLine (line, sizeof (line)); cout << line << endl;} Source.close ();}

转载请注明原文地址:https://www.9cbs.com/read-56284.html

New Post(0)