exception-handling

throw new Exception while keeping stack trace and inner exception information

左心房为你撑大大i 提交于 2019-12-07 05:25:48
问题 I have a FileSystemWatch program that I'm working on and if there's an error copying a file, I want to be able to know which file it failed on. At the same time, I'd like to be able to retain the stack trace, as well as the inner exception information. if (!found) { try { File.Copy(file, Path.Combine(watchDirectory, filename)); } catch (Exception ex) { WriteToLog(new Exception( String.Format("An error occurred syncing the Vault location with the watch location. Error copying the file {0}.

gdb - Prevent losing backtrace in a catch/rethrow situation

天大地大妈咪最大 提交于 2019-12-07 05:23:58
问题 Is it possible to re-throw an exception without losing the back-trace in gdb? Or is there a way in gdb to "back up' a few lines and back trace from there? I'm on GDB 7.7.1, the most recent. I sometimes find myself running into situations like this, needing a back trace from the original throw of the exception, and needing to comment out the try/catch parts, recompiling, and re-running in gdb. try { someFuncThatCanThrowException(); } catch(exceptionType& exception) { if(@CAN_RECOVER@) { ... }

Turn off customErrors for web service only

梦想的初衷 提交于 2019-12-07 05:16:58
问题 My ASP.NET 2.0 web app includes a web service, which throws various exceptions along with custom error messages (e.g. "You do not have access to this item" etc.). These are shown on screen, in a ASP.NET AJAX callback handler. The rest of the app is covered by some custom error pages, specified in the usual way in web.config. <customErrors mode="RemoteOnly" defaultRedirect="Error.html"> <error statusCode="404" redirect="NotFound.html" /> <error statusCode="403" redirect="NoAccess.html" /> <

How to handle free() errors in C?

旧街凉风 提交于 2019-12-07 05:02:46
问题 Suppose that I have used a free() function to free a memory that,for many reasons, I'm not allowed to. How can I stop my C application from crashing and just generate an error and continue the execution? I don't have try-catch kind of provision here (like C++/java...). Is there any way to ignore this error and continue execution? If yes, How do you do that? More importantly, is it advisable to do so (continuing execution considering this memory error occurred)? Thank you 回答1: There is nothing

How to customize uncaught exception termination behavior?

偶尔善良 提交于 2019-12-07 05:02:43
问题 In g++ and clang++ (in Linux at least) the following typical message is shown after an exception is thrown and not catch (uncaught exception): terminate called after throwing an instance of 'std::runtime_error' what(): Bye For example in: #include<stdexcept> int main(){ throw std::runtime_error("Bye"); } How do I customize the error message while still having full access to the thrown exception? The documentation (http://www.cplusplus.com/reference/exception/set_unexpected/) mentions set

The Java interface doesn't declare any exception. How to manage checked exceptions of the implementation?

可紊 提交于 2019-12-07 04:53:09
问题 Let's say I have the following Java interface that I may not modify: public interface MyInterface { public void doSomething(); } And now the class implementing it is like this: class MyImplementation implements MyInterface { public void doSomething() { try { // read file } catch (IOException e) { // what to do? } } } I can't recover from not reading the file. A subclass of RuntimeException can clearly help me, but I'm not sure if it's the right thing to do: the problem is that that exception

Is there facility for a strong guaranteed exchange in C++

折月煮酒 提交于 2019-12-07 03:38:40
I have been looking for a facility to exchange two items with a strong exception guarantee. That is; to have the exchange proceed totally, or leave the target in the initial state in the face of exceptions. Is there anything included in the current standard that allows this, I have not been able to find anything, although it appears easy to write. What I have below is a version I put together to try out what I am looking for, however it is noexcept, which is more than my requirement of "the strong" guarantee. Is appears the "strong guarantee" cannot be tested, but the noexcept guarantee can.

nested try/except in Python

北城以北 提交于 2019-12-07 03:36:07
问题 try: commands try: commands try: commands try: commands except: commands return to final commands except: commands return to final commands except: commands return to final commands except: commands final commands Which instruction have I to write in place of return to final commands to make that any except returns to the top-level instructions following the outer try? And is it an acceptable structure? Edit: Here is a toy example (I know I can do it using if s, it's only an example; suppose

@ControllerAdvice exception handler method not get called

耗尽温柔 提交于 2019-12-07 03:31:00
问题 I am working on sample demo application for Exception Handling in Spring MVC.I am trying Exception Handling With @ControllerAdvice I followed steps as describe in this link. But when i run my application i get the following error org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.test.core.ApplicationException For more details following are the classes I am working on ApplicationException.java public class ApplicationException extends

webapi and unhandled exception hook per appdomain

不问归期 提交于 2019-12-07 03:30:31
Having a WebApi 2.2 application - is it possible to make use of AppDomain's UnhandledException hook? I have a code similar to this: [assembly: OwinStartup("DevConfiguration", typeof(DevStartup))] namespace WebApi.Module { public class DevStartup { private const string ErrorEventSourceName = "WebApiHost"; private const int ErrorEventId = 600; [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)] public void Configuration(IAppBuilder app) { AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException; ... throw new Exception("some exception); }