exception-handling

Can I use std::current_exception during stack unwinding?

社会主义新天地 提交于 2019-12-09 07:35:07
问题 Should it be possible to use std::current_exception inside destructors of objects that are destroyed during stack unwinding? Documentation on cppreference says: If called during exception handling (typically, in a catch clause), captures the current exception object (...) But it's not clear for me whether stack unwinding is a part of exception handling. In some highest-ranked answer on stackoverflow author assumes that it's possible. I did some test on my compiler (g++ (Ubuntu 4.8.2-19ubuntu1

How to throw RuntimeException (“cannot find symbol”)

心不动则不痛 提交于 2019-12-09 07:31:11
问题 I'm trying to throw an exception in my code like this: throw RuntimeException(msg); But when I build in NetBeans I get this error: C:\....java:50: cannot find symbol symbol : method RuntimeException(java.lang.String) location: class ... throw RuntimeException(msg); 1 error Do I need to import something? Am I misspelling it? I'm sure I must be doing something dumb :-( 回答1: throw new RuntimeException(msg); You need the new in there. It's creating an instance and throwing it, not calling a

String.Format: Input string was not in a correct format [closed]

依然范特西╮ 提交于 2019-12-09 07:28:43
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . The following code keep giving me error saying Input string was not in a correct format, but I am pretty sure it is right, isn't it? int id = 112; String

Access violation while the program was idle - not trace information to track down the bug

老子叫甜甜 提交于 2019-12-09 07:25:23
问题 I have a program that just popped up an AV. Until now the Eureka Log could find the source code line that generated the error but now it displays only this: Access violation at address 7E452E4E in module 'USER32.dll'. Read of address 00000015. Call Stack Information: -------------------------------------------------------------------------------------------- |Address |Module |Unit |Class|Procedure/Method |Line | ---------------------------------------------------------------------------------

Should my Domain Exceptions be thrown from Application Layer?

依然范特西╮ 提交于 2019-12-09 06:25:12
问题 I'm reading Vaughn Vernon Book - Implementing Domain Driven Design. There is an example of a Project Management Application. There are aggregates like BacklogItem, Sprint, etc. If I have BacklogItemNotFoundException defined in Domain layer. Should my Rest adapter catch it and transform into NotFoundHttpResult? Or any other broken invariant exceptions like: EmailPatternBrokenException or TooManyCharactersForNameException or whatever should be handled in Rest adapter(ports&adapters architecture

Forging a stack trace in Java

梦想与她 提交于 2019-12-09 05:59:35
问题 When you use RMI in Java the remote stack trace of an exception will be prepended when you receive it, somewhat like this: ERROR Client received error when doing stuff: myapp.FooBarException: bla at server.myMethod() at rmi.callHandler() // and now, on the next line comes the client at rmi.sendCall(); at client.doServerMethod() at Thread.run() How is that kind of stacktrace "forgery" done? What do I want it for (apart from just being iterested)? Well, it would help me if I could do this:

Exceptions, and how best to retry when a connection is reset?

旧巷老猫 提交于 2019-12-09 05:42:10
问题 I have some code which connects to a URL to download a file, and then performs some processing on it. However, sometimes I am receiving the error java.net.SocketException: Connection reset . I would like to retry to download the file when I receive this error, say a maximum of 3 times before giving up on it. I would like to know what would be the best way to structure this. Does the following look ok. Does it seem acceptable to place the try-catch block inside of a while loop, or is there a

C++, is set_terminate local to every thread?

妖精的绣舞 提交于 2019-12-09 05:37:42
问题 Should set_terminate / get_terminate set a different terminate exception processor for several threads in C++ 2011 or C++ 2003? E.g. if I have program and sets terminate handler to func_1 ; then I start 3 threads. What are terminate handlers in new threads? What if in every thread I will set terminate handler to func_2 in first thread, func_3 in second thread and so on. N3242 (C++ 2011 draft) says nothing about it in [handler.functions] or in [support.exception] / [exception.terminate] PS:

Modifying or Reraising Python error in C API

给你一囗甜甜゛ 提交于 2019-12-09 04:54:26
I have a bit of code that tries to parse an object as an integer: long val = PyLong_AsLong(obj); if(val == -1 && PyErr_Occurred()) { return -1; } Here obj is a vanilla PyObject * , and PyLong_AsLong raises a very generic TypeError if obj is not an integer. I would like to transform the error message into something a bit more informative, so I would like to either modify the existing error object, or to reraise it. My current solution is to do this: long val = PyLong_AsLong(obj); if(val == -1 && PyErr_Occurred()) { PyErr_Clear(); PyErr_Format(PyExc_TypeError, "Parameter must be an integer type,

Bad Practice to run code in constructor thats likely to fail?

被刻印的时光 ゝ 提交于 2019-12-09 04:20:20
问题 my question is rather a design question. In Python, if code in your "constructor" fails, the object ends up not being defined. Thus: someInstance = MyClass("test123") #lets say that constructor throws an exception someInstance.doSomething() # will fail, name someInstance not defined. I do have a situation though, where a lot of code copying would occur if i remove the error-prone code from my constructor. Basically my constructor fills a few attributes (via IO, where a lot can go wrong) that