exception-handling

How to catch all exceptions with CherryPy?

妖精的绣舞 提交于 2019-12-05 09:56:59
I use CherryPy to run a very simple web server. It is intended to process the GET parameters and, if they are correct, do something with them. import cherrypy class MainServer(object): def index(self, **params): # do things with correct parameters if 'a' in params: print params['a'] index.exposed = True cherrypy.quickstart(MainServer()) For example, http://127.0.0.1:8080/abcde: 404 Not Found The path '/abcde' was not found. Traceback (most recent call last): File "C:\Python27\lib\site-packages\cherrypy\_cprequest.py", line 656, in respond response.body = self.handler() File "C:\Python27\lib

Setting up 32feet library

假如想象 提交于 2019-12-05 09:49:58
I'm trying to get started with this library: 32feet I have a Broadcomm Bluetooth Stack and haven't been able to figure out how to get this library set up. When I run my code, I get: Unhandled Exception: System.PlatformNotSupportedException: No supported Bluetooth protocol stack found. After digging around on their site, I found this: Installation instructions It says to copy the appropriate DLL's into the project and then run the Test32FeetWidcommWin32.exe . I've tried putting the files in every single folder in my Visual Studio project and then running that EXE, but I still get the same error

Return a value AND throw an exception?

喜欢而已 提交于 2019-12-05 09:43:20
问题 I'm working with an API that claims to return true if it succeeds, and false if it fails. But, it also claims to throw different exceptions if it fails. How can it return false and throw an exception? 回答1: It's not possible to both throw an exception and return a value from a single function call. Perhaps it does something like returning false if there's an error, but throwing an exception if the input is invalid. edit: PaulPRO posted a (now-deleted) answer pointing out that it is technically

gdb - Prevent losing backtrace in a catch/rethrow situation

旧时模样 提交于 2019-12-05 09:23:59
Is it possible to re-throw an exception without losing the back-trace in gdb? Or is there a way in gdb to "back up' a few lines and back trace from there? I'm on GDB 7.7.1, the most recent. I sometimes find myself running into situations like this, needing a back trace from the original throw of the exception, and needing to comment out the try/catch parts, recompiling, and re-running in gdb. try { someFuncThatCanThrowException(); } catch(exceptionType& exception) { if(@CAN_RECOVER@) { ... } else { throw; } } ----OR---- try { someFuncThatCanThrowException(); } catch(exceptionType& exception) {

C#: Does Visual Studio 2008 have a tool to show which Exceptions could be raised by a piece of code?

早过忘川 提交于 2019-12-05 08:57:25
问题 For example, if I'm opening a file, I know a FileNotFoundException might happen, or if I'm converting a String to double, a FormatException may happen. Obviously, if a method does both, both can be raised. Is there a way to quickly see all possible exceptions raised by a method though? Keeping track of it myself seems error prone. 回答1: It's not built into VS. There are 3rd party tools, though, like Redgate's exception hunter. Edit I'm not employed by RG, but I am a fan of their products. I've

The Java interface doesn't declare any exception. How to manage checked exceptions of the implementation?

老子叫甜甜 提交于 2019-12-05 08:57:18
Let's say I have the following Java interface that I may not modify: public interface MyInterface { public void doSomething(); } And now the class implementing it is like this: class MyImplementation implements MyInterface { public void doSomething() { try { // read file } catch (IOException e) { // what to do? } } } I can't recover from not reading the file. A subclass of RuntimeException can clearly help me, but I'm not sure if it's the right thing to do: the problem is that that exception would then not be documented in the class and a user of the class would possibly get that exception an

Should Exceptions be placed in a separate package?

你。 提交于 2019-12-05 08:54:33
问题 I am taking on a project where all the Exceptions have been placed in a separate package com.myco.myproj.exceptions . Is this good practice? 回答1: I would expect the exceptions for a package to exist within that package. e.g. com.oopsconsultancy.models.pricing would contain pricing models and related exceptions. Anything else seems a bit counter-intuitive. 回答2: It is a bad practice. It is a coincidental grouping. Packages should be coherent. Don't group exceptions, interfaces, enum, abstract

How can catched exception be null (not NullReferenceException)?

放肆的年华 提交于 2019-12-05 08:34:38
I have run into a rather weird little problem. In the following code I can not understand how e can be null ; try { //Some Code here } catch (Exception e) { //Here e is null } As far as I know, throw null will be converted to throw new NullReferenceException() . The problem seems to be related to multithreading, as removing another thread also seems to fix it. Or at least I have only seen this when the above code is run in a new thread. The whole program uses many threads and is a bit complex. Anyway my question is, how can e be null? - Hopefully the answer to that can help find the source of

How do we handle Python xmlrpclib Connection Refused?

こ雲淡風輕ζ 提交于 2019-12-05 08:27:25
I don't know what the heck I'm doing wrong here, I wrote have an RPC client trying to connect to a non-existent server, and I'm trying to handle the exception that is thrown, but no matter what I try I can't figure out how I'm supposed to handle this: def _get_rpc(): try: a = ServerProxy('http://dd:LNXFhcZnYshy5mKyOFfy@127.0.0.1:9001') a = a.supervisor return a except: return False rpc = _get_rpc() if not rpc: print "No RPC" Since there is no server running, I would expect the output to be "No RPC" but instead I get an exception: Traceback (most recent call last): File "xmlrpctest.py", line 20

Polly policy to log exception and rethrow

落花浮王杯 提交于 2019-12-05 08:25:31
I consider to use Polly to create policy to log exception and rethrow. I didn't find an existing method that allow it out of the box , but some options that I see are Fallback // Specify a substitute value or func, calling an action (eg for logging) if the fallback is invoked. Policy.Handle<Whatever>() .Fallback<UserAvatar>(UserAvatar.Blank, onFallback: (exception, context) => { _logger.Log(exception, context); throw exception; }); Question: is it ok to throw exception from Fallback? Timeout Policy.Timeout(1, T30meoutStrategy.Pessimistic, (context, timespan, task) => { task.ContinueWith(t => {