exception-handling

How to override handleUncaughtException without changing its functionallity

无人久伴 提交于 2019-12-10 13:37:51
问题 I asked this question some time back on Stackoverflow , the answer worked for me, It overrides the handleUncaughtException , I save the exception and throws the default Unfortunately app has stopped working , but when i integrated this in my app, I am facing an issue. This is the answer i got. private Thread.UncaughtExceptionHandler defaultExceptionHandler; public void registerCrash(){ defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread

Why is there a MonadMask instance for ExceptT?

六眼飞鱼酱① 提交于 2019-12-10 13:19:55
问题 In a previous question, I asked Why is there no MonadMask instance for ExceptT? and got a number of compelling answers, including from the library author, why there cannot exist a lawful instance. As of February 2018, the exceptions library does now have an instance of MonadMask for ExceptT. So now I'm asking the exact opposite question: Why are the answers to my previous question incorrect? 回答1: The documentation of the exceptions library has the answer in its docs: This method was added in

PHP rename() doesn't throws exception on error

此生再无相见时 提交于 2019-12-10 13:13:02
问题 I'm working with a php application, and there is a line that moves a file. I enclosed the method within a try...catch block so, if a error is thrown, can manage a rollback system. But the exception is never catched, so, renames throws any kind of exception? Do I need to try with another method? Thanks Code above: try{ if(rename($archivo_salida, $ruta_archivos)){ //anything; } }catch (Exception $e) //do something } 回答1: "Normal" PHP functions don't throw exceptions. Change your code to

$exception is defined in “locals”

不想你离开。 提交于 2019-12-10 13:04:29
问题 H We have log utility function that we call pretty often and I wanted to spice it up by adding a call to Server.GetLastError() and if there is an error to log as well. The log function is part of separate project so I tried to use HttpContext.Current.Server.GetLastError() (As I do for the Request, ServerVariables and Session properties). During the testing I created simple exception: int i=0, j=0; try { int k = i / j; } catch (Exception E) { Tools.CooLog("in"); } Tools.CooLog("out"); In order

Wrong WebFaultException when using a Stream and closing the stream

柔情痞子 提交于 2019-12-10 12:59:49
问题 We have a REST API, built with WCF. We handle all the exceptions backend with WebFaultException like this: throw new WebFaultException<string>(e.Message, HttpStatusCode.NotAcceptable); This works just fine except in one scenario where we do a Post, with a stream. An example of this: [WebInvoke(Method = "POST", UriTemplate = "saveUser?sessionId={sessionId}&userId={userId}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle

Correct way of transaction.rollback() with raise exception in django

こ雲淡風輕ζ 提交于 2019-12-10 12:57:46
问题 I am working with Django 1.7.1 and python 2.7, I am doing some POST requests that requires to be inside a transaction, actually I am using @transaction.atomic() decorator that makes the entire function to be inside a transaction. As far as I know, this decorator is similar to commit_on_success and makes a rollback if a database error is raised. Is it possible to raise a custom exception that makes the transaction to rollback but not using save points? I want to return a HttpResponse when the

How to get “Application Trace” instead of full verbose backtrace in Rails?

只谈情不闲聊 提交于 2019-12-10 12:49:49
问题 In Rails default error page of development environment, you can view three backtraces, 1. Application Trace, 2. Framework Trace and 3. Full Trace. But how can I get "Application Trace" in Rails controllers. Full Trace (exception.backtrace) is too much for me. Now I'm doing like this: exception.backtrace.select {|line| line =~ /myappname/i } Is this a correct way? Or are there other cooler ways to get it? 回答1: I looked up rails sources to see how it is implemented. ActionSupport has class

Python: how to avoid code duplication in exception catching?

我怕爱的太早我们不能终老 提交于 2019-12-10 12:47:18
问题 What is a good pattern to avoid code duplication when dealing with different exception types in Python, eg. I want to treat URLError and HTTPError simlar but not quite: try: page = urlopen(request) except URLError, err: logger.error("An error ocurred %s", err) except HTTPError, err: logger.error("An error occured %s", err) logger.error("Error message: %s", err.read()) In this example, I would like to avoid the duplication of the first logger.error call. Given URLError is the parent of

File.Copy() and Symbolic Links

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:46:33
问题 I want to copy a file to a new file name. Sometimes the source file might be a symbolic (file) link, created with mklink C:\MyPath\ThisIsASymbolicLink.xml C:\MyPath\ThisIsTheOriginal.xml I'm using this code: string from = @"C:\MyPath\ThisIsASymbolicLink.xml"; string to = @"C:\MyPath\WantCopyOfOriginalFileHere.xml"; File.Copy(from, to, true); However, I receive an IOException The name of the file cannot be resolved by the system. when the from file is really a symbolic link. How can I code for

Common.Logging config exception

萝らか妹 提交于 2019-12-10 12:46:00
问题 I'm getting the following exception when I try to call var log = LogManager.GetLogger(this.GetType()); A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll An unhanded exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll Additional information: Failed obtaining configuration for Common.Logging from configuration section 'common/logging'. This is a .NET 4 application with references to log4net.dll Common