LCOV - code coverage report
Current view: top level - logging/test/apps - exception_example.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 53 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 13 0

            Line data    Source code
       1              : /**
       2              :  * @file exception_example.cxx logger interface definition
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : //  See https://atlas-tdaq-monitoring.web.cern.ch/OH/refman/ERSHowTo.html
      10              : 
      11              : const char *usage = R"foo(
      12              :  Usage: %s <num>
      13              : where <num> is a number: 0 - 6.
      14              : )foo""\n";
      15              : #define USAGE usage, basename(*argv)
      16              : 
      17              : #include <libgen.h>                               // basename
      18              : #include <ers/SampleIssues.hpp>
      19              : #include <logging/Logging.hpp>
      20              : #include <string>
      21              : 
      22              : class XX
      23              : {
      24              :     public:
      25            0 :         ~XX() { TLOG_DEBUG(1) << "dtor object after raise/throw"; }
      26              : };
      27              : 
      28            0 : void foo( int except_int )
      29              : {
      30            0 :         XX xx;
      31            0 :         switch( except_int ) {
      32            0 :         case 0: {
      33            0 :                 TLOG_DEBUG(1) << "raising ers::PermissionDenied " << "somefilename";
      34            0 :                 ers::PermissionDenied permdenied(ERS_HERE, "somefilename", 0644 );
      35            0 :                 permdenied.raise();
      36            0 :         }
      37              :                 break;
      38            0 :         case 1: {
      39            0 :                 TLOG_DEBUG(1) << "raising ers::FileDoesNotExist " << "somenonfile";
      40            0 :                 ers::FileDoesNotExist doesnotexist(ERS_HERE, "somenonfilename" );
      41            0 :                 doesnotexist.raise();
      42            0 :         }
      43              :                 break;
      44            0 :         case 2: {
      45            0 :                 TLOG_DEBUG(1) << "raising ers::CantOpenFile " << "somelockedfile";
      46            0 :                 ers::CantOpenFile( ERS_HERE, "somelockedfile" ).raise();
      47              :         }
      48              :                 break;
      49            0 :         case 3:
      50            0 :                 TLOG_DEBUG(1) << "throwing std::exception";
      51            0 :                 throw std::exception();
      52            0 :                 break;
      53            0 :         case 4:
      54            0 :                 TLOG_DEBUG(1) << "throwing integer 4";
      55            0 :                 throw 4;
      56            0 :                 break;
      57            0 :         case 5: {
      58            0 :                 TLOG_DEBUG(1) << "write to address 0 - cause segv";
      59            0 :                 int *ptr=nullptr;
      60            0 :                 *ptr = 0;
      61              :         }
      62            0 :                 break;
      63            0 :         default:
      64            0 :                 TLOG_DEBUG(1) << "not throwing anything";
      65              :         }
      66            0 : }
      67              : 
      68            0 : int main(  int  argc, char      *argv[] )
      69              : {
      70            0 :         if (argc != 2) { printf(USAGE); exit(1); }
      71              : 
      72            0 :         dunedaq::logging::Logging::setup("test", "exception_example");
      73              : 
      74            0 :         TLOG_DEBUG(1) << "trying foo";
      75            0 :         try {
      76            0 :         foo( strtoul(argv[1],nullptr,0) );
      77            0 :     } catch ( ers::PermissionDenied & ex ) {
      78            0 :         ers::CantOpenFile issue( ERS_HERE, ex.get_file_name(), ex );
      79            0 :         ers::warning( issue );
      80            0 :     } catch ( ers::FileDoesNotExist & ex ) {
      81            0 :         ers::CantOpenFile issue( ERS_HERE, ex.get_file_name(), ex );
      82            0 :         ers::warning( issue );
      83            0 :     } catch ( ers::Issue & ex ) {
      84            0 :         TLOG_DEBUG( 0 ) << "Unknown issue caught: " << ex;
      85            0 :         ers::error( ex );
      86            0 :     } catch ( std::exception & ex ) {
      87            0 :         ers::CantOpenFile issue( ERS_HERE, "unknown", ex );
      88            0 :         ers::warning( issue );
      89            0 :     }
      90              : #       if 0
      91              :         catch (...) {
      92              :                 // ers::fatal( ers::Message(ERS_HERE,"unhandle exceptions would not make it to the the TRACE memory buffer") );
      93              :                 // ErrorHandler::abort(...) does StandardStreamOutput::println(std::cerr, issue, 13); ::abort();
      94              :         }
      95              : #       endif
      96              :         
      97            0 :         return (0);
      98              : }   // main
        

Generated by: LCOV version 2.0-1