User Tools

Site Tools


dev:error_handling

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:error_handling [2015/09/21 14:39] oschuettdev:error_handling [2022/08/16 16:02] (current) – typo oschuett
Line 1: Line 1:
 ====== Error Handling ====== ====== Error Handling ======
  
-In CP2K there exist three convenient macros for error handling. They are defined in [[src>cp2k/src/common/cp_common_uses.f90]], and are therefore always available. However, these macros can only be used for short messages, because of Fortran's line length limitation.+In CP2K there exist three convenient macros for error handling. They are defined in [[src>src/base/base_uses.f90]], and are therefore always available. However, these macros can only be used for **short messages** (approximately less than 7 words), because of Fortran's line length limitation.
 <code Fortran> <code Fortran>
    CPWARN("A short warning message")    CPWARN("A short warning message")
Line 8: Line 8:
 </code> </code>
  
-For longer messages one can call these two routines:+For longer messages one can use these two routines:
 <code Fortran> <code Fortran>
-   CALL cp_warn(routineP,__LINE__,"A long warning message "\\+   CALL cp_warn(__LOCATION__,"A long warning message "//
-                "which can span multiple lines and contains "\\+                "which can span multiple lines and contains "//
-                "some valuable advises for the user.")+                "some valuable advice for the user.")
  
-   CALL cp_abort(routineP,__LINE__,"A long error message "\\+   CALL cp_abort(__LOCATION__,"A long error message "//
-                 "with even more valuable advises."     +                 "with even more valuable advices."     
 </code> </code>
 +
 +<note important>
 +Messages from ''CPWARN'' and ''cp_warn'' are only printed on the first MPI-rank.\\ Warnings issued on other ranks are ignored.
 +</note>
 +
 +===== Cheat Sheet =====
 +If you want to...
 +  * print a **short warning** message, then you should use:<code Fortran> CPWARN("your short message")</code>
 +  * print a **longer warning** message, then you should use:<code Fortran> CALL cp_warn(__LOCATION__,"your lengthy message, "//&
 +              "which can even span multiple lines")</code>
 +
 +  * **stop** the program with a **short** error message, then you should use:<code Fortran> CPABORT("your short message")</code>
 +  * **stop** the program with a **longer** error message, then you should use:<code Fortran> CALL cp_abort(__LOCATION__,"your lengthy message, "//&
 +               "which can even span multiple lines")</code>
 +  * have a **simple assertion** without a custom error message, then you should use:<code Fortran> CPASSERT(your_logical_expression)</code>
 +  * have a **simple assertion** with a **short** error message, then you should use:<code Fortran> IF(.NOT.your_logical_expression) CPABORT("your short message")</code>
 +  * have a **complex assertion** with a **short** error message, then you should use:<code Fortran> IF(.NOT.your_super_complicated_logical_expression_that_takes_alot_of_space)&
 +    CPABORT("your short message")</code>
 +  * have a **lengthy assertion** with a **longer** error message, then you should use:<code Fortran> IF(.NOT.your_super_long_logical_expression_that_takes_alot_of_space)&
 +    CALL cp_abort(__LOCATION__,"your lengthy message"//&
 +                  "which again can even span multiple lines")</code>
 +
dev/error_handling.1442846356.txt.gz · Last modified: 2020/08/21 10:14 (external edit)