throw

ruby catch-throw and efficiency

寵の児 提交于 2019-12-04 08:06:13
catch in Ruby is meant to jump out of deeply nested code. In Java e.g. it is possible to achieve the same with Java's try-catch meant for handling exceptions, it is however considered poor solution and is also very inefficient. In Ruby for handling exceptions we have begin-raise-rescue and I assume it is also to expensive to use it for other tasks. Is Ruby's catch-throw really a more efficient solution then begin-raise-rescue or are there any other reasons to use it to break nested blocks instead of begin-raise-rescue ? In addition to being the "correct" way to get out of control structures,

gcc exception specification of default destructor

孤者浪人 提交于 2019-12-04 04:38:57
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 specification affect virtual destructor overriding? According to that answer the compiler is supposed to create a

Throw VS rethrow : same result?

烂漫一生 提交于 2019-12-04 02:27:13
refering to a lot of documentation on the net, particularly on SO, eg : What is the proper way to re-throw an exception in C#? there should be a difference between "throw e;" and "throw;". But, from : http://bartdesmet.net/blogs/bart/archive/2006/03/12/3815.aspx , this code : using System; class Ex { public static void Main() { // // First test rethrowing the caught exception variable. // Console.WriteLine("First test"); try { ThrowWithVariable(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } // // Second test performing a blind rethrow. // Console.WriteLine("Second test"); try

Throwing exceptions in Java

雨燕双飞 提交于 2019-12-03 19:15:24
问题 I have a question about throwing exceptions in Java, a kind of misunderstanding from my side, as it seems, which I would like to clarify for myself. I have been reading that the two basic ways of handling exception code are: 1.) throwing an exception in a try-block with "throw new ...", and catching it immediately in a catch-block - the so called try-throw-catch mechanism. 2.) throwing an exception in a method with "throw new ..." and then declaring in the header of the method that this

Convincing Swift that a function will never return, due to a thrown Exception

纵然是瞬间 提交于 2019-12-03 16:32:12
问题 Because Swift does not have abstract methods, I am creating a method whose default implementation unconditionally raises an error. This forces any subclass to override the abstract method. My code looks like this: class SuperClass { func shouldBeOverridden() -> ReturnType { let exception = NSException( name: "Not implemented!", reason: "A concrete subclass did not provide its own implementation of shouldBeOverridden()", userInfo: nil ) exception.raise() } } The problem: Because the function

Destructor that calls a function that can throw exception in C++

半腔热情 提交于 2019-12-03 12:58:21
I know that I shouldn't throw exceptions from a destructor. If my destructor calls a function that can throw an exception, is it OK if I catch it in the destructor and don't throw it further? Or can it cause abort anyway and I shouldn't call such functions from a destructor at all? Yes, that's legal. An exception must not escape from the destructor, but whatever happens inside the destructor, or in functions it calls, is up to you. (Technically, an exception can escape from a destructor call as well. If that happens during stack unwinding because another exception was thrown, std::terminate is

Is there a throws keyword in C# like in Java? [duplicate]

纵饮孤独 提交于 2019-12-03 10:21:02
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: how to use Java-style throws keyword in C#? i have a function where an exception occurs say for example private void functionName() throws Exception { // some code that might throw an exception } thanks! 回答1: No, because there are no checked exceptions in C# If you are trying to document exceptions that are thrown, use the standard xml documentation /// <exception cref="InvalidOperationException">Why it's thrown

What is generator.throw() good for?

笑着哭i 提交于 2019-12-03 03:27:44
问题 PEP 342 (Coroutines via Enhanced Generators) added a throw() method to generator objects, which allows the caller to raise an exception inside the generator (as if it was thrown by the yield expression). I am wondering what the use cases for this feature are. 回答1: Let's say I use a generator to handle adding information to a database; I use this to store network-received information, and by using a generator I can do this efficiently whenever I actually receive data, and do other things

Exception vs Assert? [duplicate]

柔情痞子 提交于 2019-12-03 01:52:18
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: design by contract tests by assert or by exception? Is there a rule of thumb to follow when deciding to use exceptions instead of asserts (or vice versa). Right now I do only throw if its something I think will happen during runtime on the user side (like a socket or file error). Almost everything else I use asserts. Also, if I were to throw an assert, what is a nice standard object to throw? IIRC there is std:

Difference between Throws in method signature and Throw Statements in Java

流过昼夜 提交于 2019-12-03 00:55:04
问题 I am trying to make it clear of the difference between Throws in method signature and Throw Statements in Java. Throws in method signature is as following: public void aMethod() throws IOException{ FileReader f = new FileReader("notExist.txt"); } Throw Statements is as following: public void bMethod() { throw new IOException(); } From my understanding, a throws in method signature is a notification that the method may throw such an exception. throw statement is what actually throw a created