项目作者: victorsndvg

项目描述 :
Fortran User Defined Exceptions Handler
高级语言: FORTRAN
项目地址: git://github.com/victorsndvg/ForEx.git
创建时间: 2016-04-26T07:07:15Z
项目社区:https://github.com/victorsndvg/ForEx

开源协议:GNU Lesser General Public License v3.0

下载


ForEx

Fortran User Defined Exceptions Handler

Experimental Code: Use it carefully! still under development

Build Status
codecov.io

License

License

What is ForEx?

ForEx is fortran 2003 project taking advance of the C preprocessor capabilities in order to emulate exception handling.

Features

  • Exception hierarchy: ForEx can handle any error object extended from the Exception base class.
  • Local flow control: throwing an exception changes the local flow. THROW performs local jumps to the end of the TRY frame or FINALLY.
  • Global handling: the exception stack is a global object under the singleton pattern.
  • Single THROW call per scope:
    • Single throw call per local TRY scope.
    • Single throw call per local CATCH scope.
    • Single throw call per local FINALLY scope.
  • Re-throwing: a exception can be raised again in the CATCH scope.
  • Re-throwing Backtrace: an exception saves the stack of contexts where it has been throwed.
  • Handle throwed exceptions: CATCH iterate over all the exceptions looking for the first that matches the same class.
  • CATCH precedence: multiple CATCH calls in the same TRY frame are executed sequencially.
  • Automatic exception stack cleaning when CATCH: if several exceptions has been thrown along the program, only one of them will be handled in the next CATCH call.
  • Customizable catching action: Exception class contains the Catch procedure to customize the action performed when cathing it.
  • Automatic Backtrace of non handled exceptions: going out of the main TRY/ENDTRY scope with non handled exceptions in the stack causes exception backtrace flush.

How to get ForEx

git clone https://github.com/victorsndvg/Forex.git

Compilation

ForEx compile with GNU Fortran compiler 5.1 (and newer versions) and Intel Fortran compiler 15.0.1 (and newer versions).

ForEx uses CMake as a portable compilation system.

The easiest way to compile ForEx under Linux is:

  1. $ cd ForEx
  2. $ mkdir build
  3. $ cd build
  4. $ cmake ../
  5. $ make

To compile ForEx under Windows use de equivalent commands

Remember, ForEx take advantage of the C preprocessor. To include it in your project, you have to add the preprocessor flags while compiling.
Preprocesor flags depending on the compiler vendor:

  • GNU Fortran: -cpp
  • Intel Fortran: -fpp
  • IBM XLF: -qsuffix=f=f90:cpp=f90

Using ForEx in your program

  1. program test
  2. USE ForEx
  3. implicit none
  4. #include "ExceptionHandler.i90"
  5. TRY
  6. ! Variable allocation
  7. if(Error) then
  8. THROW(Exception(Code=-1, Message='An error message')
  9. endif
  10. CATCH(Exception, Ex)
  11. call Ex%Print()
  12. FINALLY
  13. ! Variable deallocation
  14. ENDTRY
  15. end program test