Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Howto try catch
#1
Hello.

I want to exceute some commands in a try environment. How can I do this in python?

Thanks
Consuli
Reply
#2
try:
   # what you want to try
except except_condition:
   # Except code here
Reply
#3
The most important part is to give user a meaningful message Snooty
>>> 1 / 0
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
ZeroDivisionError: division by zero
>>> 
>>> try:
...     1 / 0
... except ZeroDivisionError:  
...     print('Are you a stupid donkey,you can not divide by 0')
...     
Are you a stupid donkey,you can not divide by 0
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  howto get size of a ctk image? janeik 2 780 Oct-03-2023, 03:49 AM
Last Post: janeik
  Howto do motion event on solely window and not the widgets on it? janeik 3 789 Jul-11-2023, 12:10 AM
Last Post: deanhystad
  try catch not working? korenron 2 811 Jan-15-2023, 01:54 PM
Last Post: korenron
  Multiprocessing queue catch get timeout Pythocodras 1 2,240 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  twisted: catch return from sql wardancer84 0 1,501 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  how to catch schema error? maiya 0 1,808 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 4,593 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 2,101 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  try catch question ,get data from main code korenron 7 3,102 Nov-03-2020, 09:28 AM
Last Post: korenron
  catch input type error mcmxl22 5 2,968 Aug-11-2019, 07:33 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020