Skip to content
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

Exception in callback breaks program #24

Closed
chr0x6eos opened this issue Nov 12, 2019 · 4 comments
Closed

Exception in callback breaks program #24

chr0x6eos opened this issue Nov 12, 2019 · 4 comments

Comments

@chr0x6eos
Copy link

When an exception in the callback function connect(self)/disconnect(self) occurrs, the callback function never leaves and the program is stuck.

@DhruvKhemani
Copy link
Contributor

DhruvKhemani commented Nov 12, 2019

Hi, can you please give a short example. I'll look over it and if needed, work on a fix. There might also be a workaround depending on your use case:
Have you tried catching the exception, that is being raised in the callback function, in the callback function itself?

@chr0x6eos
Copy link
Author

Yes, after catching the exception the program prints the error message and does not move further in the code.

@DhruvKhemani
Copy link
Contributor

That is supposed to happen, since you should code what should happen next or if there was some mistake with recognizing the card then the card should be taken off the reader and put on it again.

If you want to see a full example implementation for raising exceptions in the callback you can look at my Praesidium demo under the function card_connect (line 251).

The following wasn't tested so it probably doesn't work. It was just written quickly to give an overview of how it should work:

def some_function_that_does_something():
    * Do something *
    try:
        * Do something that can raise an exception *
    except Exception as details:
        print('Your error: ' + details)
    * Continue doing something * 

def connect():
    try:
        * connect to card code *
        some_function_that_does_something()
    except Exception as details:
        print('Error while connecting to card: ' + details)
    finally:
        * Optional: Do some cleanup*

If you raise an exception in some_function_that_does_something() outside of the try: then that exception will land in the connect() function and I don't think you want that.

The exception in connect() should be used to indicate mistakes with the card since you want the program to not continue if for example a wrong card is put on the reader (because any card on the reader can trigger the callback, its your job to check if its a Blockchain Security 2Go card).

I hope i was able to clarify some things...

@andreasWallnerIFX
Copy link
Collaborator

issue seems to be solved - closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants