Message: Re: How to catch G4Exceptions ? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: How to catch G4Exceptions ? 

Forum: Run Management
Re: Question How to catch G4Exceptions ? (Julien Bolmont)
Date: Feb 04, 18:19
From: Jonathan Madsen <Jonathan Madsen>

Geant4 does not "throw" exceptions thus a "try/catch" block will not do anything. If a G4Exception is designated a FatalException (see G4ExceptionSeverity.hh) than the application will exit.

See line 100 in where "abort()" is called.

The only way to "catch" this would be to implement a signal handler that gets invoked when SIGABRT occurs but that is not recommended as implementing a signal-handler will interfere with signal-handler used in visualization.

This generally is not viewed as a problem though, since if you are using GDML for your geometry, this should be fatal. If you are trying to read a GDML file and if it is empty/not available, you do something else, just check if the file exists:

  std::ifstream in(filename);
    G4cout << "File '" << filename << "' does not exist" << G4endl;

or check if the file is empty:

  std::ifstream::pos_type filesize(const char* filename)
      std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
      return in.tellg(); 

On Thu, 22 Nov 2018 14:52:29 GMT, Julien Bolmont wrote:

> Hi,
> I'd like to know a clean way to properly catch a G4Exception. Namely, I
> use GDML geometries and I'd like to catch the exception which is thrown
> when validation is on and when I have no network connexion. This
> exception leads to the following message :
> G4GDML: VALIDATION ERROR! fatal error during schema scan at line: 2
> -------- EEEE ------- G4Exception-START -------- EEEE -------
> *** G4Exception : InvalidRead
>       issued by : G4GDMLRead::Read()
> ERROR - Empty document or unable to validate schema!
>         Check Internet connection is ON in case of schema
>         validation enabled and location defined as URL in
>         the GDML file - geometries/thin_cylinder_vacuum_geometry.gdml - being imported!
>         Otherwise, verify GDML schema server is reachable!
> *** Fatal Exception *** core dump ***
>  **** Track information is not available at this moment
>  **** Step information is not available at this moment
> -------- EEEE -------- G4Exception-END --------- EEEE -------
> *** G4Exception: Aborting execution ***
> My idea is to put the call to G4GDMLParser::Read() into a "try" block
> and then in the "catch" block, try to Read the file again, but with
> schema validation turned off.
> I do not use exceptions very often so I don't really know how to use
> G4Exceptions.
> Any help would be really appreciated !
> Thanks a lot, Julien

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: How to catch G4Exceptions ?   (Tom Roberts - Feb 04, 20:31)
 Add Message Add Message
to: "Re: How to catch G4Exceptions ?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]