-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error stack class/object #95
Comments
Thanks for the proposal. Can you give an example how would this be used in practice? Does one have to call Shouldn't better debugging and stacktraces capability be rather built into compilers themselves? |
I'll update the original post with an example
Unless someone can think of a better way to do this, then, "yes": Either the caller or callee must call Upon further consideration, the design with the lease typing that does not require an object oriented decorator is to pass 3 extra arguments to each procedure:
Then the procedure can call push and pop on entry/exit and provide its own name as an optional argument. I'm going to update my original post to reflect this. For other classes & objects that take an OOD/OOP approach you may be able to implement a decorator pattern where the classes being implemented use the
Absolutely! But I'm tired of waiting 😄. I should open a new issue over in the other J3 repo. In particular the following would be helpful in letting users write their own error handling, if we cannot get error handling into the language itself:
Or, better still for error handling:
|
I am doing what I can. I could have been a lot further along, but I felt putting my time into In the meantime, here is how to get nice stacktraces from user code: https://github.com/trilinos/Trilinos/blob/4ddae567dc74b55dfa2fb7eb27c04a1808ba2475/packages/teuchos/core/src/Teuchos_stacktrace.hpp I implemented that 10 years ago. Since then, there seem to be a few other libraries that can do that:
I think they all follow basically the same approach. I have not tested that with Fortran, only C and C++, but I think it would work. |
I completely agree! Thanks for the hard work! |
I was editing my original post but lost the edits upon navigating to another link. I'll try to refine my ideas and add a usage example tonight. |
I have an implementation of something that does pretty much what you're asking for here. https://gitlab.com/everythingfunctional/erloff It uses a functional programming approach, and has some conveniences for callers to deal with errors/messages that come back. It enables subroutines to remain pure as well. Here are a couple projects I've made use of it as well: Let me know if you have any questions about it. |
I would like to implement an error stack class/object. This will be helpful for addressing #76 (message for errors inside of stdlib). The reasons why this is useful are that:
pure
(or maybeelemental
too, I'll have to think more carefully about that) procedures, and then handle them at a higher levelpure
proceduresPerhaps this should be part of #72 (standard assert and macros) or the existing
stdlib_experimental_error.f90
or perhaps it should be its own module.I'm waiting, in part, for #69 (string handling routines) to get to a point where there's some consensus, to take a crack at implementing that before proposing an implementation for this. String handling will be important for the manipulations required.
Sketch interface prototype
I like to let CMake ad a per-source-file definition, something like
THIS_FILE
that holds the relative path to the file in the source directory. It could fallback to__FILE__
when using manual makefiles. The benefit over__FILE__
is two fold:Also, one or more arguments could be made optional. It would be wonderful if there was a way to query the name of the current scope in Fortran and if the programmer didn't need to make two separate calls, one to the callee and one push info onto the error stack. You could add file name, line number and error_stack arguments to all procedures and then the callee could push the data onto the stack as an alternative to the caller doing it.
Feedback, advice and suggestions welcome here.
The API needs some further thought, which is why I'd like feedback from others. In an ideal world, it would be awesome to have this act as a decorator and not have to call the
push
method before the caller calls the callee or not have to pass the file name and line number if the callee does the push.Preprocessor macro expansion could automatically expand multiple actual arguments on calls to other stdlib procedure to pass in the stack object, file name and line number but seems a bit too magic for my liking.
The text was updated successfully, but these errors were encountered: