throw

Boost symbol not found

南笙酒味 提交于 2019-11-27 07:01:36
问题 I'm trying to compile/port an older version of OpenOffice. It uses Boost v1.34.1, which is part of the source tree. The error message is as follows: Undefined symbols: "boost::throw_exception(std::exception const&)", referenced from: boost::detail::shared_count::shared_count<ScToken>(ScToken*)in detfunc.o ld: symbol(s) not found Boost is new to me, and I haven't been able to find much online to help me understand this. From the error message, I understand that I probably need to link a

In C++, if throw is an expression, what is its type?

别说谁变了你拦得住时间么 提交于 2019-11-27 05:06:38
问题 I picked this up in one of my brief forays to reddit: http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/ Basically, the author points out that in C++: throw "error" is an expression. This is actually fairly clearly spelt out in the C++ Standard, both in the main text and the grammar. However, what is not clear (to me at least) is what is the type of the expression? I guessed " void ", but a bit of experimenting with g++ 4.4.0 and Comeau yielded this code:

What is the difference between throw and throw with arg of caught exception?

被刻印的时光 ゝ 提交于 2019-11-27 02:07:46
问题 Imagine two similar pieces of code: try { [...] } catch (myErr &err) { err.append("More info added to error..."); throw err; } and try { [...] } catch (myErr &err) { err.append("More info added to error..."); throw; } Are these effectively the same or do they differ in some subtle way? For example, does the first one cause a copy constructor to be run whereas perhaps the second reuses the same object to rethrow it? 回答1: Depending on how you have arranged your exception hierarchy, re-throwing

Incorrect stacktrace by rethrow

夙愿已清 提交于 2019-11-27 00:42:05
I rethrow an exception with "throw;", but the stacktrace is incorrect: static void Main(string[] args) { try { try { throw new Exception("Test"); //Line 12 } catch (Exception ex) { throw; //Line 15 } } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.ToString()); } Console.ReadKey(); } The right stacktrace should be: System.Exception: Test at ConsoleApplication1.Program.Main(String[] args) in Program.cs:Line 12 But I get: System.Exception: Test at ConsoleApplication1.Program.Main(String[] args) in Program.cs:Line 15 But line 15 is the position of the "throw;". I have tested this with

What causes the different behaviors between “var” and “let” when assign them a returned value of a function which throws an error

佐手、 提交于 2019-11-26 23:38:26
问题 Please find the code in the image below. 1. Assign the returned value of a function, which throws an error actually, to the variable 'withLet' that declared by using keyword 'let'. 2. call 'withLet', an error occured: 'withLet is not defined'. 3. try to assert 'withLet' using 'let', an error shows that 'withLet' has already been declared. But the paradox is not exist for 'var' (Please find in the following image). I'm curious about what caused the different behaviors between these two

Difference between C++03 throw() specifier C++11 noexcept

喜你入骨 提交于 2019-11-26 21:28:04
Is there any other difference between throw() and noexcept apart from being checked runtime and compile time respectively ? Wikipedia C++11 article suggests that C++03 throw specifiers are deprecated. Why so, is noexcept capable enough to cover all that at compile time ? [Note: I referred this question and this article , but couldn't got the solid reason of deprecation.] Nicol Bolas Exception specifiers were deprecated because exception specifiers are generally a terrible idea . noexcept was added because it's the one reasonably useful use of an exception specifier: knowing when a function won

What is the difference between `throw new Error` and `throw someObject`?

隐身守侯 提交于 2019-11-26 21:09:49
I want to write a common error handler which will catch custom errors thrown on purpose at any instance of the code. When I did throw new Error('sample') like in the following code try { throw new Error({'hehe':'haha'}); // throw new Error('hehe'); } catch(e) { alert(e); console.log(e); } Log shows in Firefox as Error: [object Object] and I couldn’t parse the object. For the second throw the log shows as: Error: hehe Whereas when I did try { throw ({'hehe':'haha'}); } catch(e) { alert(e); console.log(e); } the console showed as: Object { hehe="haha"} in which I was able to access the error

Java unchecked/checked exception clarification

谁说我不能喝 提交于 2019-11-26 20:21:35
问题 I've been reading about unchecked versus checked questions, none of the online resources have been truly clear about the difference and when to use both. From what I understand, both of them get thrown at runtime, both of them represent program states that are outside the expected bounds of the logic, but checked exceptions must be explicitly caught while unchecked ones do not. My question is, suppose for argument's sake I have a method that divides two numbers double divide(double numerator,

What can you throw in Java?

好久不见. 提交于 2019-11-26 20:04:55
问题 Conventional wisdom says you can only throw objects that extend Throwable in Java, but is it possible to disable the bytecode verifier and get Java to compile and run code that throws arbitrary objects - or even primitives? I looked up the JVM's athrow and it will pop the first objref on the operand stack; but would it check if said reference points to a Throwable at run time? 回答1: It depends on your JVM implementation. According to the Java VM specification it is undefined behavior if the

Why does throwing 2 exceptions in a row not generate an unreachable code warning?

拜拜、爱过 提交于 2019-11-26 17:47:45
问题 Why do the following lines of code not create a compiler warning? void Main() { throw new Exception(); throw new Exception(); } As I see it, the compiler should inform you that the second throw exception cannot be reached. 回答1: It is clearly a compiler bug, and it was introduced in C# 3.0 -- right around the time that I heavily refactored the reachability checker. This is probably my bad, sorry. The bug is completely benign; basically, we just forgot a case in the warning reporter. We