exception

std::out_of_range exception is not thrown

醉酒当歌 提交于 2021-01-27 11:31:06
问题 // The following code works fine, throwing a std::out_of_range exception: std::vector<double> vd{ 1.5 }; try { int i{ -1 }; double d = vd.at(i); // exception is thrown } catch (std::out_of_range& re) { std::cout << "Exception is " << re.what() << std::endl; // invalid vector subscript } If I access vector elements in a for loop with an invalid index, no std::exception is thrown although I use .at() . Why is the std::out_of_range exception not thrown? // in a for loop, this does not throw the

Why does this contextmanager behave differently with dict comprehensions?

拈花ヽ惹草 提交于 2021-01-27 07:21:50
问题 I have a context decorator that has side effects when it's done. I've noticed that the side effects don't occur if I use a dict comprehension. from contextlib import contextmanager import traceback import sys accumulated = [] @contextmanager def accumulate(s): try: yield finally: print("Appending %r to accumulated" % s) accumulated.append(s) def iterate_and_accumulate(iterable): for item in iterable: with accumulate(item): yield item def boom_unless_zero(i): if i > 0: raise RuntimeError("Boom

Rhino Mocks Exception Expect #1 Actual #0 : Need assistance

南笙酒味 提交于 2021-01-27 06:58:47
问题 I've have searched on this and it seems to be a catch all, unfortunately everything I've read doesn't help figure it out. Here is the class: public interface IMockInterface { MockClass MockedMethod(); MockClass MockThis(); } public class MockClass : IMockInterface { public virtual MockClass MockedMethod() { MockClass returnValue; returnValue = new MockClass(); returnValue.SomeMessage = "Not mocked"; return returnValue; } public MockClass MockThis() { MockClass mock; MockClass returnValue;

Why do you need to catch “Exception” but not the Subclass “RuntimeException”?

帅比萌擦擦* 提交于 2021-01-27 01:31:01
问题 The below picture shows that "Checked" and "Unchecked" Exceptions are subclasses of Exception . I find it confusing that you need to catch an Exception but you don't need to catch a RuntimeException , which directly inherits from Exception . Is there a reason that the devs didn't let us throw Exceptions without needing to catch them? More specifically: Why can you ignore only RuntimeExceptions and it's children? Why wasn't there a Class introduced called CheckedException extends Exception and

Why do you need to catch “Exception” but not the Subclass “RuntimeException”?

假如想象 提交于 2021-01-27 01:30:13
问题 The below picture shows that "Checked" and "Unchecked" Exceptions are subclasses of Exception . I find it confusing that you need to catch an Exception but you don't need to catch a RuntimeException , which directly inherits from Exception . Is there a reason that the devs didn't let us throw Exceptions without needing to catch them? More specifically: Why can you ignore only RuntimeExceptions and it's children? Why wasn't there a Class introduced called CheckedException extends Exception and

Catching native C++ exceptions in C#

大城市里の小女人 提交于 2021-01-26 09:34:30
问题 I have some native C++ class libraries that I have wrapped up in C++ .NET which I then call from C# (three layers!). I can throw exceptions from C++ .NET and happily catch them in C#. The trouble is that the only way I can catch my native C++ exceptions is by catching System.Exception, which is fine but in the conversion from std::exception to System.Exception I lose the vast majority of the information about the error (for example the error message!). I can catch the native exception in the

socket简易聊天室

孤人 提交于 2021-01-24 01:42:01
服务器端 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * @version 2012-7-26 下午04:04:18 **/ public class server { // 服务器端口 private static final int SERVERPORT = 54321; // 客户端连接 private static List<Socket> mClientList = new ArrayList<Socket>(); // 线程池 private ExecutorService mExecutorService; //

UnsupportedOperationException on Collection

流过昼夜 提交于 2021-01-20 17:33:47
问题 While studying the Collection API, we find that some methods ( add , remove ,...) may throw a java.lang.UnsupportedOperationException if the current implementation of the Collection does not support those functionalities. Is there,actually, in the JDK, a concrete Collection that does not support those methods ? Thanks a lot for your answers. 回答1: The obvious examples are the implementations returned from, say, Collections.unmodifiableCollection() and other similar methods. Methods that would

Handling Windows-specific exceptions in platform-independent way

岁酱吖の 提交于 2021-01-18 04:02:00
问题 Consider the following Python exception: [...] f.extractall() File "C:\Python26\lib\zipfile.py", line 935, in extractall self.extract(zipinfo, path, pwd) File "C:\Python26\lib\zipfile.py", line 923, in extract return self._extract_member(member, path, pwd) File "C:\Python26\lib\zipfile.py", line 957, in _extract_member os.makedirs(upperdirs) File "C:\Python26\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 267] The directory name is invalid: 'C:\\HOME\\as\ \pypm

Handling Windows-specific exceptions in platform-independent way

霸气de小男生 提交于 2021-01-18 03:59:05
问题 Consider the following Python exception: [...] f.extractall() File "C:\Python26\lib\zipfile.py", line 935, in extractall self.extract(zipinfo, path, pwd) File "C:\Python26\lib\zipfile.py", line 923, in extract return self._extract_member(member, path, pwd) File "C:\Python26\lib\zipfile.py", line 957, in _extract_member os.makedirs(upperdirs) File "C:\Python26\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 267] The directory name is invalid: 'C:\\HOME\\as\ \pypm