exception-handling

C++/GCC: How to detect unhandled exceptions in compile time

做~自己de王妃 提交于 2019-12-13 16:12:53
问题 Introduction: In Java, if you do not catch an exception, your code doesn't even compile, and the compiler crashes on unhandled exception. Question: Is there a way to tell GCC to be "strict" as Java in this case, and to raise an error or at least a warning on unhandled exception? If not - are there IDEs (for Unix, please) that can highlight such cases as a warning? 回答1: It is not possible in C++. Exception specification is a part of a function declaration but not a part of its type . Any

catch errors within generator and continue afterwards

二次信任 提交于 2019-12-13 15:59:17
问题 I have an iterator which is supposed to run for several days. I want errors to be caught and reported, and then I want the iterator to continue. Or the whole process can start over. Here's the function: def get_units(self, scraper): units = scraper.get_units() i = 0 while True: try: unit = units.next() except StopIteration: if i == 0: log.error("Scraper returned 0 units", {'scraper': scraper}) break except: traceback.print_exc() log.warning("Exception occurred in get_units", extra={'scraper':

MVC ELMAH v/s Application_Error

旧城冷巷雨未停 提交于 2019-12-13 15:56:16
问题 Background I had [HandleError] in place in my MVC web app for exception handling but later it couldn't handle some exceptions so I was suggested to move on to the alternative Application_Error (my SO Post) I also ended up using ELMAH which seems better. Well, ELMAH rocks! But I was unable to find how to show formatted exception with it (like I do with Application_Error) ELMAH v/s Application_Error ELMAH - Provides (almost) out of the box exception logging and other features like email. Its

Catching exceptions caused by temporary network errors

柔情痞子 提交于 2019-12-13 15:18:02
问题 I have to download some URLs, and it can happen that during the operations some exception may occur, like java.net.NoRouteToHostException . I consider it a temporary error exception, as the download can succeed if you retry it after some time. So, I'd like to catch all those exceptions related to temporary errors, and I've started with these: java.net.NoRouteToHostException , java.net.SocketException Can you list other exceptions like these? 回答1: java.net.SocketException is the parent of java

Exception to throw when expecting a null value?

前提是你 提交于 2019-12-13 15:11:15
问题 If I am expecting a null value and get a defined value (within a getter of a property) and want to throw an exception, what would be the proper way to do this in csharp? Is there anything defined already that makes sense in this situation? 回答1: My guess would be: throw new ArgumentException("Parameter was expected to be null, value was provided."); ArgumentOutOfRangeException might also work, but is typically used when there is a well defined range rather than null vs. not null. 回答2: I would

getting the exception class name in python?

蓝咒 提交于 2019-12-13 14:34:17
问题 I want to generate a string in an exception handler that contains the name of the exception, and any arguments passed...oretty much the final output that one gets with Traceback. For example, if raise bar.FnordError("message") is called, in the exception handler, I want to produce the string: "bar.FnordError: message" I want it to work for built in exceptions, as well as exceptions in the current and other modules. This is what I came up with, but it doesn't seem very pythonic. def this_is

else clause in try statement… what is it good for [duplicate]

南楼画角 提交于 2019-12-13 14:12:40
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Python try-else Comming from a Java background, I don't quite get what the else clause is good for. According to the docs It is useful for code that must be executed if the try clause does not raise an exception. But why not put the code after the try block? It seems im missing something important here... 回答1: The else clause is useful specifically because you then know that the code in the try suite was

Any value in catching an exception and immediately raising it again? [duplicate]

一笑奈何 提交于 2019-12-13 14:08:23
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Does a exception with just a raise have any use? Is there any value to re-raising an exception with no other code in between? try: #code except Exception: raise I was recently looking through some code and saw a few blocks like these with nothing extra in the except block but another raise. I assume this was a mistake and poor decision making, am I right? 回答1: I've seen similar code before in a (set of) horrible

What should be the strategy to handle the sql exceptions?

末鹿安然 提交于 2019-12-13 13:44:35
问题 I have a multi-tier application. DAL -> BAL -> Business Gateway ->UI. If a foreign key or unique constraint exception occurs at DAL, How should we recognize which exception is this and what error message to show the user. Should we use error number to identify this. Second question : How should we propogate this error to UI. We are thinking to throw this exception to BAL and BAL would encapsulate the error and return a response(not exception) to UI. Is it the right approach. 回答1: DAL

strange problems with C++ exceptions with mingw

亡梦爱人 提交于 2019-12-13 12:27:50
问题 I have encountered a strange problems with exceptions using mingw and managed to cut it down to the following example: #include <iostream> #include <fstream> #include <cstdlib> using namespace std; void test(int a) { if (a < 0) { throw std::ios_base::failure("a < 0"); } } void test_file(std::string const & fName) { std::ifstream inF(fName.c_str(), std::fstream::in); if (!inF) { cout << "file error -> throwing exception" << endl; throw ios_base::failure("could not open input file '" + fName +