async def add_profile(self) -> Profile | What goes here? :
try:
await self.connection.commit()
except aiosqlite.IntegrityError as error:
return error
async with rows as cursor:
result = await cursor.fetchone()
if result is not None:
return Profile(*result)
else:
# Return a custom error
``` I've omitted some code to avoid some bloat, but I want to be able to return an error if I get a `aiosqlite.IntegrityError` and return an error if `if result is not None:` Where can I read about how I would do this?
#๐ Returning a custom error.
18 messages ยท Page 1 of 1 (latest)
@stark geyser
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
why would you return an error?
Profile | aiosqlite.IntegrityError | YourCustomError, but why do you want to return it?
So I can display to my user that something went wrong. Is that the wrong way to go about it?
it should be raised, and caught outside the function
in which case sure, you could print something custom
but don't return the error just to check if there is an error through non-idiomatic means
!e
class MyCustomError(Exception):
pass
def f():
raise MyCustomError
try:
f()
except MyCustomError:
print("womp-womp, something went wrong")
@pallid sky :white_check_mark: Your 3.12 eval job has completed with return code 0.
womp-womp, something went wrong
I see.
That makes a lot more sense than what I was gonna do ๐
Thank you
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.