-
Notifications
You must be signed in to change notification settings - Fork 7
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
How do I add an exception? if Appname is not found #11
Comments
You could try like from AppOpener import open
try:
open("XYZ", output=True)
except Exception as e:
print(str(e)) # prints "XYZ was not found"
print("HELLO") |
Actually the output=True, just prints when the app is not found or when a app is not running. But if it threw an error then I can do something like: try:
open("XYZ", throw_error=True)
except:
# Now i can do whatever I want here like
# using the pyttsx3 library I can make it speak something
engine = pyttsx3.init()
engine.say("The App you want to open was not found")
engine.runAndWait() It just expands the usability of the module. Previously we couldn't do that because it was just a print statement. |
You seem beginner in python, here how you may do this without throw_error attribute: from AppOpener import open
try:
open("XYZ", output=True)
except Exception as e:
print(str(e)) # prints "XYZ was not found"
print("DO NOW WHATEVER YOU WANNA DO") I would pull back the changes :) Btw, thanks for the pull request ✨🤗 |
Actually your code dosen't even throw an exception error. from AppOpener import *
try:
open("XYZ", output=True)
except Exception as e:
pass Even if you don't print the exception it'll still print his line "XYZ" was not found. Explained later why then try this: from AppOpener import *
try:
open("XYZ", output=True)
except Exception as e:
print("DID IT THROW AN ERROR?") Then check the output. In the output you won't see this "DID IT THROW AN ERROR?" if output:
''' Instead of printing this line it should throw an error '''
print(f"{self.upper()} NOT FOUND... TYPE (LS) for list of applications.") Because printing to the console is not the same as raising an error like in my pr. Please do try this in your version of the code and then tell me if it worked because it shouldn't work and I'm pretty sure it's not working for anyone. Try and put anything in the except block it won't get executed in your version of the code, and then try the same in my version of the code. |
import io
from contextlib import redirect_stdout
from AppOpener import open
output = io.StringIO()
with redirect_stdout(output):
open("XYZ", output=True)
if " NOT FOUND" in output.getvalue():
print("DO WHATEVER YOU WANNA DO") but thats the long route... I will keep the |
Yeah, that is a solution but it's not really developer friendly and it's pretty expected by developers nowdays that the code will throw an error. That is why throw_error attribute is necessary. Thanks for making this module btw love it 💖 |
The app opener when using the open() function does not throw an error and rather prints to terminal. This makes it hard to do certain things such as speak something using speech recognition library when like the app is not found
The text was updated successfully, but these errors were encountered: