Where do you like to catch exceptions and why?

前端 未结 9 1488
别跟我提以往
别跟我提以往 2020-12-03 08:31

Where do you like to catch exceptions and why?

I\'m interested in seeing where people find it useful to put their try/catch blocks in the hope that some general patt

9条回答
  •  清歌不尽
    2020-12-03 09:32

    I always put a catch in main() as a catch of last resort:

    int main( int argc, char** argv ) {
        try {
            Application application( argc, argv );
            return application.result();
        }
        catch ( const std::exception& exception ) {
            fprintf( stderr, "%s.\n", exception.what() );
        }
    }
    

提交回复
热议问题