-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Capturing exceptions inside Kv #1572
Comments
Capturing exception and try/catch is not part of the language, and i doubt it would be. Using python for that is actually the best solution for handling issues, or you can use the general to indicate if you want to let it pass or not (http://kivy.org/docs/api-kivy.base.html?highlight=exceptionhandler#kivy.base.ExceptionHandler). But the second solution will still break all the stack call. If you have specific use cases, please share them. I'm playing a long time with kv from the start, and never got the feeling that this would be needed. Kv is meant for describing the UI, control part should (most of the time) stay in python. |
Thank you for showing me the exceptionhandler, I didn't see it. However I think this could be automated through Kv, I will post some usage cases tomorrow, as it's late now. |
Here are my use cases: A more explicit if statement similar to this could also be useful, even if it's implicitly allowed with "x if True else y". |
This language / feature is not appealing is the first read. My point is a such error should be done in python directly. If you have a mymodule.get_image(), then ensure the get_image() always return a valid image. About using try/catch for conditionnal statement within the kv language itself is weird. Conditionnal and looping are part of the wishes to the user, but no "good" way have been found yet. Your approach is mixing kv / python / kv / python, and i'm sure it make the langage even more un-readable. But at least, we have another example to look at. |
The methods you call from the kv are not necessarily part of the application. I could use #import and import an external module that eventually raises an exception in one of its methods. Creating a method in the application just to catch the exceptions in that method and prevent the app from crashing is a bit silly, isn't it? Probably loops are not really useful in kivy, but who knows, maybe someone could find them useful in future... |
For what it's worth, I would write it as: Image:
source: mymodule.get_image()
size: "64dp", "64dp"
on_error: self.source = "atlas://data/images/defaulttheme/image-missing" |
That seems too vague, i.e. to what does the I think we should close this issue as this is unlikely to happen, at least in the way it's currently proposed. |
The use case snippet is a bit unfortunate, it seems to be referring to handling a not found image, which has nothing to do with this thread because a wrong file path produces a white texture, not an exception. For the original proposal, i don't see a need for try except in kv either, normally, kv should never fail in that way, and if it does, the code should be fixed, not exceptions handled. Exceptions originating from python function calls can also be handled on the python side. |
Hello,
I suggested this in another issue, but I want to repropose it as I think it will be a lot useful. It happens sometimes that something inside the Kv raises an unwanted exception that you cannot avoid. The only alternative is creating some python function that contains a try-except and prevents the app from crashing, but this makes the kv language itself unuseful.
Will you do that? For example one could wrap from a few properties to an entire tree in a try-except; the builder checks, when an exception occurs, if there was a try-excepts and avoids it in that case, or reraises it if there wasn't any.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: