exception-handling

how to time-out gracefully while downloading with python

╄→尐↘猪︶ㄣ 提交于 2019-12-20 23:01:28
问题 I'm downloading a huge set of files with following code in a loop: try: urllib.urlretrieve(url2download, destination_on_local_filesystem) except KeyboardInterrupt: break except: print "Timed-out or got some other exception: "+url2download If the server times-out on URL url2download when connection is just initiating, the last exception is handled properly. But sometimes server responded, and downloading is started, but the server is so slow, that it'll takes hours for even one file, and

how to time-out gracefully while downloading with python

给你一囗甜甜゛ 提交于 2019-12-20 22:58:16
问题 I'm downloading a huge set of files with following code in a loop: try: urllib.urlretrieve(url2download, destination_on_local_filesystem) except KeyboardInterrupt: break except: print "Timed-out or got some other exception: "+url2download If the server times-out on URL url2download when connection is just initiating, the last exception is handled properly. But sometimes server responded, and downloading is started, but the server is so slow, that it'll takes hours for even one file, and

how to catch exception of MVC view?

江枫思渺然 提交于 2019-12-20 19:57:49
问题 In controller, try...catch can catch exception. How to catch exception in view? for example, a view may have code like: <%= Html.Encode(Model.MyID)%> If Model is null, you will get exception when access the view. where to catch the exception and redirect user to a error page with user-friendly error message? 回答1: Simply add the [HandleError] attribute to the top of your Controller class. This way, any exception generated by your Controller will be handled and the user will be presented /Views

Are exceptions in php really that useful?

为君一笑 提交于 2019-12-20 19:44:15
问题 3 days ago I started rewriting one of my scripts in OOP using classes as a practice after reading a lot about the advantages of using OOP. Now I'm confused weather I should use exceptions or not. They seem to make my work harder and longer. My application check if the data was sent through an Ajax request or not then uses that info through the script. Check this example : /* * The older way */ if($ajaxEnabled) { $error = errorWrap('Ajax error'); } else { $error = errorWithBackLinkWrap('NoAjax

C# try {} catch {}

痞子三分冷 提交于 2019-12-20 19:39:45
问题 hi and thanks for reading. im a newbie in programming and C# and sockets programming. in my code i try and catch problems to provide fault tolarence in my app. the following: catch (ArgumentNullException e) { OnNetworkEvents eventArgs = new OnNetworkEvents("Network Unavailable", e.Message); OnUpdateNetworkStatusMessage(this, eventArgs); } catch (EncoderFallbackException e) { OnNetworkEvents eventArgs = new OnNetworkEvents("Network Unavailable", e.Message); OnUpdateNetworkStatusMessage(this,

Dealing with (cross-process) exceptions in Android custom content provider

◇◆丶佛笑我妖孽 提交于 2019-12-20 18:42:19
问题 I have a custom content provider in my Android app that works reasonably well. I expect other apps to also access my content provider. I would like some clean way to communicate exceptions and errors, but as far as I can tell the Android content provider framework doesn't provide any way to propagate exceptions across processes. How should I indicate an exception state to my caller? Do I have to somehow encode it into my returned data and rely on clients to check for it? Is there any

Handle undeclared dict key in Python

旧巷老猫 提交于 2019-12-20 17:35:40
问题 In my Ruby application I have a hash table: c = {:sample => 1,:another => 2} I can handle the table like this: [c[:sample].nil? , c[:another].nil? ,c[:not_in_list].nil?] I'm trying to do the same thing in Python. I created a new dictionary: c = {"sample":1, "another":2} I couldn't handle the nil value exception for: c["not-in-dictionary"] I tried this: c[:not_in_dictionery] is not None and it is returning an exception instead of False. How do I handle this? 回答1: In your particular case, you

how do you handle and parse JPA persistence exceptions to provide meaningfull message to user

。_饼干妹妹 提交于 2019-12-20 16:35:12
问题 I am fairly new to JPA and want to find best practices when handling persistence exceptions from JPA for things like say, unique constraint violations which can be addressed by the user. There are tons of examples on how to write JPA apps, but almost nothing on how to hand exceptions kicked out by them. :/ For example registering a user, the person enters an email address that is already in active use by the system and gets a constraint violation: try { em.persist(credentials); } catch (javax

Why do AppDomain exceptions invariably terminate the application?

时光总嘲笑我的痴心妄想 提交于 2019-12-20 15:22:36
问题 This is related to a previous question. What I'm trying to understand now is how come UI thread exceptions can be prevented from terminating the application while non-UI exceptions can't be. For reference, see this example. Most importantly, what I would like to be able to do in that case is "silently" terminate the process--without displaying the Windows dialog box that asks whether I'd like to send an error report or not. This is my AppDomain UnhandledExceptionHandler: private static void

Can gdb be used to backtrace when exceptions are caught?

最后都变了- 提交于 2019-12-20 11:35:24
问题 I have just started using c++ exceptions and want to get it right. What I have in mind is to generate some sort of backtrace information when exceptions are caught. Initially I had ideas similar to Call-stack for exceptions in C++ but eventually figured out that's not quite good. I have also read How to generate a stacktrace when my gcc C++ app crashes but do not want to add more complexity to my current project. Since, I only need the backtracing when in debug mode, I was hoping I could be