exception-handling

Exception Handling guideline- Python vs Java

断了今生、忘了曾经 提交于 2019-12-05 02:29:06
I am original Java developer, for me, checked Exception in Java is obviously/easy enough for me to decide to catch or throw it to the caller to handle later. Then it comes Python, there is no checked exception, so conceptually, nothing forces you to handle anything(In my experience, you don't even know what exceptions are potentially thrown without checking the document). I've been hearing quite a lot from Python guys that, in Python, sometimes you better just let it fail at runtime instead of trying to handle the exceptions. Can someone give me some pointers regarding to: what's the guideline

JAX-WS Soap Faults not appearing in WSDL

别来无恙 提交于 2019-12-05 02:13:43
I am creating a web service using JAX-WS (I am creating this using the Java to WSDL approach). Im having trouble getting my exception to work as I require. I have created the following exception class: @WebFault public class MyWebServiceException extends SOAPFaultException { private static final long serialVersionUID = 8234753208722614057L; protected MyWebServiceException(SOAPFault fault) { super(fault); } protected MyWebServiceException(SOAPFault fault, Throwable throwable) { this(fault); super.setStackTrace(throwable.getStackTrace()); } } This allows me to have the following in my SOAP

java.net.BindException: Address already in use: JVM_Bind <null>:80

有些话、适合烂在心里 提交于 2019-12-05 02:07:59
I am getting binding exception while starting the Tomcat server. I tried to kill the process that which is using '80' as couple of processes are using it. Getting error, while killing process id is '0': ERROR: The process with PID 0 could not be terminated. Reason: This is critical system process. Taskkill cannot end this process. How to fix this? I don't need to use another port to run the tomcat server. Setting Tomcat to listen to port 80 is WRONG , for development the 8080 is a good port to use. For production use, just set up an apache that shall forward your requests to your tomcat. Here

Why is else clause needed for try statement in python? [duplicate]

无人久伴 提交于 2019-12-05 01:57:16
This question already has an answer here: Python try-else 19 answers In Python the try statement supports an else clause, which executes if the code in try block does not raise an exception. For example: try: f = open('foo', 'r') except IOError as e: error_log.write('Unable to open foo : %s\n' % e) else: data = f.read() f.close() Why is the else clause needed? Can't we write the above code as follows : try: f = open('foo', 'r') data = f.read() f.close() except IOError as e: error_log.write('Unable to open foo : %s\n' % e) Won't the execution proceed to data = f.read() if open does not raise an

Continue loop iteration after exception is thrown

核能气质少年 提交于 2019-12-05 01:50:25
Let's say I have a code like this: try { for (int i = 0; i < 10; i++) { if (i == 2 || i == 4) { throw new Exception("Test " + i); } } } catch (Exception ex) { errorLog.AppendLine(ex.Message); } Now, it's obvious that the execution will stop on i==2 , but I want to make it finish the whole iteration so that in the errorLog has two entries (for i==2 and i==4 ) So, is it possible to continue the iteration even the exception is thrown ? Just change the scope of the catch to be inside the loop, not outside it: for (int i = 0; i < 10; i++) { try { if (i == 2 || i == 4) { throw new Exception("Test "

Hoptoad v. Exceptional v. exception_notification v. exception_logger

若如初见. 提交于 2019-12-05 01:46:13
Which of the following exception notification solutions is the best? Exceptional Hoptoad exception_notification exception_logger I use hoptoad and have had nothing but a positive experience, I highly recommend it. On a high traffic site we use an internal messaging queue for errors, then pump those back up to hoptoad. Not a massive fan of hoptoad, it's too easy to ignore messages. The internal queue makes it nice and easy to change service if we need to, and prevents our app from being dependant on an external application within a request cycle (we log some errors to hoptoad even if the

Propagating AccessDeniedException in Spring Security

↘锁芯ラ 提交于 2019-12-05 01:11:23
问题 In my web application I am using Spring Security and Spring MVC. I have secured a couple of methods with @Secured annotation and configured Spring Security in such a way that when one of those methods is accessed without the proper role, the user is taken to the login page. However, I do not want that behaviour when the offending request comes from Ajax, so I implemented the custom @ExceptionHandler annotated method to determine the request's context. This is my exception handler:

Why does XmlDocument.LoadXml throw System.Net.WebException?

主宰稳场 提交于 2019-12-05 00:55:09
Why does System.Xml.XmlDocument.LoadXml method throw System.Net.WebException ? This is really mind boggling crazy, if MSDN was right, LoadXml should at most give me a System.Xml.XmlException . Yet I have weird exceptions like: The underlying connection was closed: The connection was closed unexpectedly. Dim document As New XmlDocument document.LoadXml("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><x></x>") MsgBox(document.LastChild.Name) What on earth is causing the exception ? Edwin gave you the solution, and I'm

Is it always a bad practice to catch System.Exception?

こ雲淡風輕ζ 提交于 2019-12-05 00:53:39
Please consider the following piece of code, which throws three different exceptions (namely, System.Configuration.ConfigurationErrorsException , System.FormatException and System.OverflowException ): int SomeInt = Convert.ToInt32(ConfigurationManager.AppSettings["SomeIntValue"]); The exceptions are different, and so in practice I should have three different catch blocks to handle each particular exception. However, in this particular case, all exceptions are handled the same way: a log is written to, say, EventViewer, and a message informing of a configuration error is displayed... In this

How to restart schedule when scheduleWithFixedDelay throws an exception?

最后都变了- 提交于 2019-12-05 00:51:33
问题 I use ScheduledExecutorService to schedule some tasks which need to run periodically. I want to know whether this code works to recover the schedule when an exception happens. ScheduledExecutorService service = Executors.newScheduledThreadPool(1); this.startMemoryUpdateSchedule(service);//See below method //Recursive method to handle exception when run schedule task private void startMemoryUpdateSchedule(ScheduledExecutorService service) { ScheduledFuture<?> future = service