exception

What if an object passed into std::swap throws an exception during swapping?

 ̄綄美尐妖づ 提交于 2021-02-08 14:15:41
问题 The C++ standard guarantees that std::swap will throw no exception. However, what if an object to swap throws an exception during swapping? Next, how should the caller find an exception has happened? and what measures should the caller take? PS: It is very common that a constructor throws an exception. struct A { A(const A&) { throw 1; } A& operator =(const A&) { throw 2; return *this; } }; int main() { A a1, a2; std::swap(a1, a2); // An exception happened, but the caller doesn't know. // How

What if an object passed into std::swap throws an exception during swapping?

痞子三分冷 提交于 2021-02-08 14:14:44
问题 The C++ standard guarantees that std::swap will throw no exception. However, what if an object to swap throws an exception during swapping? Next, how should the caller find an exception has happened? and what measures should the caller take? PS: It is very common that a constructor throws an exception. struct A { A(const A&) { throw 1; } A& operator =(const A&) { throw 2; return *this; } }; int main() { A a1, a2; std::swap(a1, a2); // An exception happened, but the caller doesn't know. // How

Throw/do-not-throw an exception based on a parameter - why is this not a good idea?

那年仲夏 提交于 2021-02-08 13:38:52
问题 I was digging around in MSDN and found this article which had one interesting bit of advice: Do not have public members that can either throw or not throw exceptions based on some option. For example: Uri ParseUri(string uriValue, bool throwOnError) Now of course I can see that in 99% of cases this would be horrible, but is its occasional use justified? One case I have seen it used is with an "AllowEmpty" parameter when accessing data in the database or a configuration file. For example:

Why doesn't Perl 6's try handle a non-zero exit in shell()?

心已入冬 提交于 2021-02-08 13:24:11
问题 This try catches the exception: try die X::AdHoc; say "Got to the end"; The output shows that the program continues: Got to the end If I attempt it with shell and a command that doesn't exit with 0, the try doesn't catch it: try shell('/usr/bin/false'); say "Got to the end"; The output doesn't look like an exception: The spawned command '/usr/bin/false' exited unsuccessfully (exit code: 1) in block <unit> at ... line ... What's going on that this makes it through the try? 回答1: The answer is

What on earth is “Self-suppression not permitted” and why is Javac generating code which results in this error?

╄→尐↘猪︶ㄣ 提交于 2021-02-08 12:21:58
问题 This new Java 7 try-with-resources construct is quite nice. Or at least, it was nice until an exception came along and ruined my day. I've finally managed to boil it down to a reproducible test which uses nothing but JUnit+jMock. @Test public void testAddSuppressedIssue() throws Exception { Mockery mockery = new Mockery(); final Dependency dependency = mockery.mock(Dependency.class); mockery.checking(new Expectations() {{ allowing(dependency).expectedCall(); allowing(dependency).close(); }});

Class takes no arguments (1 given) [duplicate]

雨燕双飞 提交于 2021-02-08 12:13:17
问题 This question already has answers here : Python interpreter error, x takes no arguments (1 given) (4 answers) “<method> takes no arguments (1 given)” but I gave none (3 answers) Python:Function takes no arguments (2 answers) Closed 3 years ago . class MyClass: def say(): print("hello") mc = MyClass() mc.say() I am getting error: TypeError: say() takes no arguments (1 given) . What I am doing wrong? 回答1: This is because methods in a class expect the first argument to be self . This self

Is it possible to use try with resources along with an input stream?

て烟熏妆下的殇ゞ 提交于 2021-02-08 11:47:19
问题 When implementing try with resources I am creating a Scanner object via Scanner sc = new Scanner(System.in) within () of the try statement. In the try block, I am prompting the user to enter a numeric value, reading it via sc.nextLine() and utilizing parseDouble to convert it to a method. I utilize a do-while loop to re-prompt the user to enter a value if an invalid value was entered initially. However, if the user enters an invalid value, the input stream closes, NumberFormatException is

Java handle invalid request Mapping urls including decodings

你说的曾经没有我的故事 提交于 2021-02-08 11:29:41
问题 in my apiController, I have @Controller @RequestMapping("api/v1/myservice") @Slf4j public class APIController { @RequestMapping(value = "/validAPI1", method = RequestMethod.GET) @ResponseBody public String validAPI1() { return "success"; } } I want to catch invalid incoming API requests, such as /api/v1/myservice/random124 , and this can be done by adding a method at the end: @RequestMapping(value = "/**", method = RequestMethod.GET) @ResponseBody public String handleInvalidAPIReq() { return

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V

走远了吗. 提交于 2021-02-08 08:33:28
问题 I am getting this run-time error: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V And part of stack trace: Caused By: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.j ava:915) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:575) at

android java.net.UnknownHostException: Unable to resolve host

纵然是瞬间 提交于 2021-02-08 08:12:02
问题 So, I'm trying to send POST requests to an IP adress, but I've found a problem way before that. To check if there's a working connection to the internet I have the following method called when creating the Activity: public void checkInternectConnection() { AsyncTask.execute(() -> { try { InetAddress inAddress = InetAddress.getByName("https://google.com"); if (inAddress.equals("")) { networkAvilable = true; } else { networkAvilable = false; } } catch (Exception e) { e.printStackTrace();