throw

VC++ 2008/2010: is throw() or __declspec(nothrow) a better choice?

℡╲_俬逩灬. 提交于 2019-12-11 08:56:20
问题 When using VC++ 2008 and 2010, which marker is better to use to indicate a function won't throw exceptions: throw() (C++ standard) __declspec(nothrow) (MS extension) I read a few older forum discussions where people said that using throw() may actually force the compiler to generate additional code to catch exceptions in case the function does throw (against the marker). Their advice is not to use throw() but use __declspec(nothrow) instead, since the compiler can actually use it for

Java catching exceptions and subclases

ⅰ亾dé卋堺 提交于 2019-12-11 03:57:37
问题 Hello, In Java if a method like BufferedReader.read() says it can throw an IOException and I try to catch a FileNotFoundException and an IOException in two catch blocks, what catch blocks will be entered if the file doesn't exist? Does it enter only the most specific or both? 回答1: The first coded catch that matches the exception will be entered. Edited to incorporate comment from Azodius For example: try { bufferedReader.read(); } catch (FileNotFoundException e) { // FileNotFoundException

How can I have multiple exception in a single throw java docs tag?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 14:13:19
问题 I am trying to add a JavaDoc in my code. I need to add multiple exception in a single throw. When I add below, it only recognizes NullPointerException not the IllegalArgumentException . Is there any way to provide multiple exception in a single throw tag so that it can recognize both, when I place my mouse on the method? @throws NullPointerException, IllegalArgumentException when invalid userId, timeout is passed Or I need to do it like this? By this, I am repeating same comment twice.

Re-throw an exception inside catch block

隐身守侯 提交于 2019-12-10 13:19:43
问题 Can anyone please confirm me if this information is correct or not: In C++, inside catch block we can re-throw an exception using throw statement, but the thrown exception should have the same type as the current caught one. 回答1: The rethrown exception can have a different type. This compiles and runs correctly on VS2012 // exceptions #include <iostream> using namespace std; int main () { try{ try { throw 20; } catch (int e) { cout << "An exception occurred. Exception Nr. " << e << '\n';

Function exceptions specification and standard exceptions - foo() throw(Exception)

佐手、 提交于 2019-12-10 07:47:11
问题 In C++ you may declare function with exception specification like this: int foo() const throw(Exception); I found those two links: http://www.cplusplus.com/doc/tutorial/exceptions/ and http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr156.htm But several things end up unanswered... Question 1: why to add exception specification? Will it bring any performance increase? What will be different for compiler? Because it seems

gcc exception specification of default destructor

旧街凉风 提交于 2019-12-09 15:57:12
问题 class A { public: virtual ~A() { } }; class B : virtual public A { public: ~B() throw() {} }; class C : public B { }; int main(int argc, char * argv []) { return 0; } That code gives the following error: error: looser throw specifier for ‘virtual C::~C()’ error: overriding ‘virtual B::~B() throw ()’ on my debian testing ( gcc (Debian 4.6.0-10) 4.6.1 20110526 (prerelease) ) but compiles without errors on previous gcc versions ( 4.5 on my debian system again). How does an exception

What is the benefit to limiting throws allowed by a C++ function? [closed]

旧街凉风 提交于 2019-12-09 08:58:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . What is the benefit of declaring the possible exception-throws from a C++ function? In other words, what does adding the keyword throw

Returning after throwing exceptions

做~自己de王妃 提交于 2019-12-08 15:50:12
问题 Is it in any way beneficial to return a value after throw ing an exception? If not, can the return statement be left out and is it somehow possible to remove compiler error C4715: not all control paths return a value ? Thanks in advance. Edit: (sample code) for (ushort i = 0; i < itsNumUnits; ++i) if (unitFormation[i] == unit) { return unitSetup[i]; } else throw unit; return 0; 回答1: There is no need to return a value after exception throw. If you have this error, you should check the paths

catching error event message from firefox

 ̄綄美尐妖づ 提交于 2019-12-07 17:02:19
问题 I can't find a way to catch the error message under firefox: window.addEventListener("error", handleException, false); ... function handleException(e) { alert(e); return false; } ... <script> throw new Error('sdasd'); </script> This enters very well the handleException method however the e parameter is an error event under firefox and I don't know how to get the associated message . In chrome for instance, I get either the message through e.message because after the error bubbles up to not

An exception throw has type `Nothing`?

烂漫一生 提交于 2019-12-07 14:15:46
问题 As stated here - Chapter 7 of Programming in Scala, Built-in Control Structures, 7.4 Exception handling with try expressions: In Scala, throw is an expression that has a result type. Technically, an exception throw has type Nothing . You can use a throw as an expression even though it will never actually evaluate to anything. This little bit of technical gymnastics might sound weird, but is frequently useful in cases like the previous example. One branch of an if computes a value, while the