exception-handling

Rescue all errors of a specific type inside a module

点点圈 提交于 2019-12-22 05:16:35
问题 I have a module in which I am performing all of my encryption/decryption tasks for a project. I would like to catch any OpenSSL::Cipher::CipherError exceptions that occur in this module so that I can handle them. Is it possible to do something like rescue_from OpenSSL::Cipher::CipherError, :with => :cipher_error inside of a module? 回答1: I've investigated a little and came with a solution. You said you have a module in which you do your encryption. I'm guessing that module represents a

Optional printing of stack trace in Java

我与影子孤独终老i 提交于 2019-12-22 05:04:40
问题 I am creating a java application in which there is a possibility that exceptions might be thrown. I am handling these exceptions in a try-catch block and printing appropriate messages so that the business users don't have to see the ugly stack trace in case of a failure. But now when I debug, I would like to invoke the JAR file in such a way that it will print the stack traces for me, so that I can know where exactly the problem lies. Can someone enlighten me on how this can be achieved? 回答1:

How to Handle Exceptions and Error Messages in Laravel 5?

强颜欢笑 提交于 2019-12-22 05:03:02
问题 When i get this error: QueryException in Connection.php line 620: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry can i handle it with my own flash error message instead of: Whoops, looks like something went wrong 回答1: You have two ways to handle exceptions and show a custom response: 1) Let the framework handle them for you: If you don't handle exceptions by yourself, Laravel will handle them in the class: App\Exceptions\Handler In the render method you can intercept

Ruby - Execution expired

£可爱£侵袭症+ 提交于 2019-12-22 04:59:35
问题 I have a ruby code like this: begin doc = Nokogiri::HTML(open(url).read.strip) rescue Exception => ex log.error "Error: #{ex}" end And I am getting log as: ERROR -- : Error: execution expired I want block re-execute until it success. How can I do it? 回答1: I'll expand on my comment a little bit. You can use retry to go back to the begin : begin doc = Nokogiri::HTML(open(url).read.strip) rescue Exception => ex log.error "Error: #{ex}" retry end That will keep trying (and logging errors) until

Cancel task.delay without exception or use exception to control flow?

故事扮演 提交于 2019-12-22 04:49:28
问题 I'm unsure about two possibilities to react to an event in my code. Mostly I'm concerned about which one needs less resources. I have a method with an observer registered to an eventproducer . If the eventproducer returns something, the method exits and the caller of the method starts the method again (you can think of it as a kind of a long polling). The eventproducer sometimes fires lots of events per seconds and sometimes rests for minutes. The first approach was to await a delay of 500ms

Exceptions Not Being Thrown In Visual Studio

谁说我不能喝 提交于 2019-12-22 04:21:24
问题 For some reason my exceptions arent being thrown anymore in Visual Studio. I get the error in JSON on the response, but Visual Studio in debug mode no longer throws an error and stops Visual Studio at that error when it happens. I have looked into posts like this: Visual Studio not stopping on an exception being thrown But I just want to reset where I was before, not enable exceptions one by one. 回答1: To reset the exceptions settings, go to Debug>Exceptions and click "Reset All." You can also

Exceptions Not Being Thrown In Visual Studio

℡╲_俬逩灬. 提交于 2019-12-22 04:21:07
问题 For some reason my exceptions arent being thrown anymore in Visual Studio. I get the error in JSON on the response, but Visual Studio in debug mode no longer throws an error and stops Visual Studio at that error when it happens. I have looked into posts like this: Visual Studio not stopping on an exception being thrown But I just want to reset where I was before, not enable exceptions one by one. 回答1: To reset the exceptions settings, go to Debug>Exceptions and click "Reset All." You can also

Catch a javascript error in an external script file

▼魔方 西西 提交于 2019-12-22 04:16:30
问题 I have a bit of JavaScript (Jquery Tools' Overlay) which may throw an exception when dropped on a page that uses it incorrectly, and I'm trying to handle it gracefully. I have a general window.onerror handler to rescue these errors and report them back to the server, however that's not getting triggered. I also cannot wrap a try/catch around this code, as it's being included as a remote script in HTML. Any ideas on how you can rescue errors that an external script throws? UPDATE : Here's the

When is KeyboardInterrupt raised in Python?

夙愿已清 提交于 2019-12-22 04:12:17
问题 All the docs tell us is, Raised when the user hits the interrupt key (normally Control-C or Delete ). During execution, a check for interrupts is made regularly. But from the point of the code, when can I see this exception? Does it occur during statement execution? Only between statements? Can it happen in the middle of an expression? For example: file_ = open('foo') # <-- can a KeyboardInterrupt be raised here, after the successful # completion of open but prior to the try? --> try: # try

How to distinguish programmatically between different IOExceptions?

北城余情 提交于 2019-12-22 04:09:26
问题 I am doing some exception handling for code which is writing to the StandardInput stream of a Process object. The Process is kind of like the unix head command; it reads only part of it's input stream. When the process dies, the writing thread fails with: IOException The pipe has been ended. (Exception from HRESULT: 0x8007006D) I would like to catch this exception and let it fail gracefully, since this is expected behavior. However, it's not obvious to me how this can robustly be