throw

Strange debugger behaviour in async method

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 05:15:12
问题 When I stepped over breakpoints in my code I have encountered strange behaviour of debugger: public async Task DoSomeWork() { await Task.Run(() => { Thread.Sleep(1000); }); var test = false; if (test) { throw new Exception("Im in IF body!"); } } Debugger goes into if body. It's remarkable that the exception is not really thrown but just looks like it is. So you can't reproduce that if you place breakpoint right on throw . You must place it above and step down to the if body to catch it. The

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

 ̄綄美尐妖づ 提交于 2019-11-28 03:21:44
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: void f() { } struct S {}; int main() { int x = 1; const char * p1 = x == 1 ? "foo" : throw S(); // 1

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

送分小仙女□ 提交于 2019-11-28 02:07:19
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 situations. It's quite wired that 'not defined' an 'already been declared' describe a same variable. let

Java unchecked/checked exception clarification

自闭症网瘾萝莉.ら 提交于 2019-11-27 20:19:05
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, double denominator) { return numerator / denominator; } and a method that requires divison somewhere

What can you throw in Java?

大兔子大兔子 提交于 2019-11-27 19:57:29
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? John Kugelman It depends on your JVM implementation. According to the Java VM specification it is undefined behavior if the object is not Throwable . The objectref must be of type reference and must refer to an object

When to catch the Exception vs When to throw the Exceptions?

馋奶兔 提交于 2019-11-27 17:27:08
I have been coding in Java for a while now. But sometimes, I don't understand when I should throw the exception and when should I catch the exception. I am working on a project in which there are lot of methods. The hierarchy is something like this- Method A will call Method B and Method B will call some Method C and Method C will call Method D and Method E. So currently what I am doing is- I am throwing exceptions in all the methods and catching it in Method A and then logging as an error. But I am not sure whether this will be the right way to do it? Or should I start catching exceptions in

Does throw inside a catch ellipsis (…) rethrow the original error in C++?

大兔子大兔子 提交于 2019-11-27 15:35:48
问题 If in my code I have the following snippet: try { doSomething(); } catch (...) { doSomethingElse(); throw; } Will the throw rethrow the specific exception caught by the default ellipsis handler? 回答1: Yes. The exception is active until it's caught, where it becomes inactive. But it lives until the scope of the handler ends . From the standard, emphasis mine: §15.1/4: The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in 3.7.4.1.

“rxjs” observable.throw is not a function - Angular4

给你一囗甜甜゛ 提交于 2019-11-27 10:46:54
问题 I've been learning Angular 4 and everything was going smoothly until I tried to implement catch handling in a service. I'm trying to use "rxjs" catch and throw but I've got an undefined function error in my console. import { Injectable } from '@angular/core'; import { Http } from "@angular/http"; import { Observable } from 'rxjs/observable'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; import { AppError } from "../app/common/app.error"; import { NotFoundError } from "

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

若如初见. 提交于 2019-11-27 09:00:43
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. 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 generate the reachability information correctly; as others have noted, we correctly trim out the unreachable code

Difference between throw and throws in Java? [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-11-27 08:08:44
This question already has an answer here: Exception handling : throw, throws and Throwable 8 answers Can any one clearly state the difference between throw and throws in Java exception handling with an example? I have tried googling but couldn't arrive at a conclusion. Pls help Nirav Prajapati throws clause is used to declare an exception and throw keyword is used to throw an exception explicitly. If we see syntax wise then throw is followed by an instance variable and throws is followed by exception class names. The keyword throw is used inside method body to invoke an exception and throws