I'm using a library in which all examples are in the style "single function with 1000 lines". Trying to understand and structure it a bit better by wrapping some stuff in functions, which can then be easily reused.
However, all the subroutines in the library take three extra arguments:
- error code
- error string
- alternate return label in case of error
Wrapping this up in a function means I have to have alternate return labels in every single one, and either have the functions in the same "program" section as the main example (so copy-pasting code), or also have the error code/string arguments for all my functions. This gets very messy.
I haven't used fortran 90 very much, and have more of a c++ background, but my idea to avoid this was:
- put the error message/code in a module, with setters/getters and use the module as some giant global error variable
- in the same module, have some kind of throw/catch exception handling, giving the exception label only once, and then jumping to it on an error call.
However, gfortran does not seem to have the longjmp or (i)setjmp calls.
Questions:
- Is there some way to use this in gfortran?
- Is this a good idea in general, what are alternatives for error handling?
My current code can be seen at:
However, all the subroutines in the library take three extra arguments:
- error code
- error string
- alternate return label in case of error
Wrapping this up in a function means I have to have alternate return labels in every single one, and either have the functions in the same "program" section as the main example (so copy-pasting code), or also have the error code/string arguments for all my functions. This gets very messy.
I haven't used fortran 90 very much, and have more of a c++ background, but my idea to avoid this was:
- put the error message/code in a module, with setters/getters and use the module as some giant global error variable
- in the same module, have some kind of throw/catch exception handling, giving the exception label only once, and then jumping to it on an error call.
However, gfortran does not seem to have the longjmp or (i)setjmp calls.
Questions:
- Is there some way to use this in gfortran?
- Is this a good idea in general, what are alternatives for error handling?
My current code can be seen at: