![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Posts: 14
Rep Power: 0
![]() |
Error Trapping and putting a program on a web site not as a file download.
Ok. I need a simple error trapping code please. And how do you place a program on a web page without it being a downloadable file? After I get my answers I'm out of your hair until I finish the tutorial. Which didn't have anything about error trapping. Thanks
__________________
Scientists prove this. Scientists prove that. They discover this, discover that. Though it seems there will be nothing left the discover, wrongo. Look beyond. I see no boundaries. The only boundaries, are your determination, your imagination, your intuition, and your knowledge. But it all started with a dream. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Error trapping code? You may have to be more specific. But you catch errors with try and except.
#invalid_variable = 42 try: print invalid_variable except: print "Variable Doesn't Yet Exist" print 'Done' And for an ftp at least, you can go ...right click > properties > permission > uncheck read access... if you are the owner. But that means no one can view or download it except you. |
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Yes, try and except as shown in Sane's example, but make sure you tell the interpreter what kind of error you're excepting - faster to run, and faster to read (when you come back to a piece of code after months you won't be blindly asking yourself what kind of error you're trying to except).
In that example it would be: try:
print invalid_variable
except NameError:
print "Variable doesn't exist yet.."Quote:
|
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
although i dont no if python has it, you should have a finally block, which is always run, to close db connections etc, and also a catchall exception otherwise there might be one you can miss.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Yep, Python supports finally. As for a catchall exception.. probably not a good idea, as you won't know how precisely to clean up or fix the problem that's arisen.
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
Yeah i understand that one, but i normally put one in for the errors i dont no that might occur to close the program effectivly and not have things still stuck in memory, and also log the error, for later purposes of fixing it.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jul 2005
Posts: 14
Rep Power: 0
![]() |
Thanks guys.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|