exception-handling

How to intercept method which handles its own exceptions using AspectJ

雨燕双飞 提交于 2019-12-12 09:09:02
问题 I'm trying add some monitoring when some specific exception occurs. For example, if I have an aspect like this: @Aspect public class LogAspect { @AfterThrowing(value = "execution(* *(..))", throwing = "e") public void log(JoinPoint joinPoint, Throwable e){ System.out.println("Some logging stuff"); } } And test class: public class Example { public void divideByZeroWithCatch(){ try{ int a = 5/0; } catch (ArithmeticException e){ System.out.println("Can not divide by zero"); } } public void

How do I 'globally' catch exceptions thrown in object instances

萝らか妹 提交于 2019-12-12 09:04:50
问题 I am currently writing a winforms application (C#). I am making use of the Enterprise Library Exception Handling Block, following a fairly standard approach from what I can see. IE : In the Main method of Program.cs I have wired up event handler to Application.ThreadException event etc. This approach works well and handles the applications exceptional circumstances. In one of my business objects I throw various exceptions in the Set accessor of one of the objects properties set { if (value >

Diagnosing CLR errors in Windows Event Viewer

↘锁芯ラ 提交于 2019-12-12 08:53:48
问题 We have an .NET desktop application that crashed in production. How do we diagnose the error? I'd like to know the type of exception that occurred, the error message, and the stack trace. Because the exception wasn't handled by our code, we received the "This application has encountered a problem and needs to close" Windows message box. The only option was to close, there was no debug button. This MSDN article suggested looking in the Windows Event registry. I checked there, and here's the

Avoid try/catch on Android

时光总嘲笑我的痴心妄想 提交于 2019-12-12 08:51:52
问题 I am new in Android environment and I have started writing some code to execute some queries on a database. When I have to handle exceptions I don't know what the appropriate way is to do it - out of Android I used to use throws declaration on methods but it seems that throws isn't allowed in android? Just try-catch ? I say this because eclipse doesn't suggest me adding throws declaration like when I am out of Android environment, I guess that it is related to extends Activity . So what is

How to retry just once on exception in python

烈酒焚心 提交于 2019-12-12 08:48:42
问题 I might be approaching this the wrong way, but I've got a POST request going out: response = requests.post(full_url, json.dumps(data)) Which could potentially fail for a number of reasons, some being related to the data, some being temporary failures, which due to a poorly designed endpoint may well return as the same error (server does unpredictable things with invalid data). To catch these temporary failures and let others pass I thought the best way to go about this would be to retry once

Unhandled Exception checker plugin for Visual Studio

谁说我不能喝 提交于 2019-12-12 08:48:29
问题 I would like to be able, at compile time, to ask any given method what possible Exceptions might get thrown by invoking it. The list of Exceptions should include any uncaught Exception that might get thrown in any nested method invokation. Caught Exceptions should not be included in the list as I'm only interested in the Exceptions that might bubble up to my own code. Does a plug-in for Visual Studio with that feature or something similar exist? It would be great if this plug-in were also

Best way to handle object's fields validation => Either / Try (scala 2.10) / ValidationNEL (scalaz)

[亡魂溺海] 提交于 2019-12-12 08:48:08
问题 Let's assume an object constructed using a builder pattern. This builder pattern would contain a build method focusing on fields validation and then on conversion to the targeted type. This validation could be implemented using: Either[FailureObject, TargetObject] type Try[TargetObject] (new feature from Scala 2.10) Validation[FailureObject, TargetObject] or ValidationNEL[FailureObject, TargetObject] from scalaz library I read that one of the main advantages of Validation over Either type is

Catching a specific WebException (550)

谁说胖子不能爱 提交于 2019-12-12 08:46:39
问题 Let's say I create and execute a System.Net.FtpWebRequest . I can use catch (WebException ex) {} to catch any web-related exception thrown by this request. But what if I have some logic that I only want to execute when the exception is thrown due to (550) file not found ? What's the best way to do this? I could copy the exception message and test for equality: const string fileNotFoundExceptionMessage = "The remote server returned an error: (550) File unavailable (e.g., file not found, no

Only break for certain exception types

自闭症网瘾萝莉.ら 提交于 2019-12-12 08:45:58
问题 I know Exception Handling is a very important thing and we are doing it in all our projects. The main reason is to log errors that occur at the customers. This works fine and is not problem at all. But while I am still coding and running the application with Visual Studio I don't want any exception handling at all. I want the debugger stop right at the line the application crashed and not in some error logger I wrote. And I don't want to forward exceptions with throw! But I am still looking

How does the JVM know where to catch an exception at runtime?

放肆的年华 提交于 2019-12-12 08:37:18
问题 From my understanding, throw is a primative jvm command. When this is called, the JVM "checks if the current call stack can catch it". if it can't, then java simply pops the call stack almost exactly as if a return was called. then the jvm "checks if the current call stack can catch it" and so on recursively. My question: how is it algorithmically possible for the JVM to know where in the call stack can catch a given exception? Is there metadata stored in each call stack entry mapping