exception-handling

Catches communication exception instead of custom fault exception - WCF

烈酒焚心 提交于 2019-12-21 21:36:18
问题 On Server I'm throwing the exception like this. catch(SqlException exception) { if (exception.Message.Contains("Custom error from stored proc")) { //Exception to be thrown when authentication fails. throw new FaultException<MyServiceFault>(new MyServiceFault { MessageText = exception.Message }); } } And on client end I'm catching the exception catch(FaultException<MyServiceFault> faultException) { } Here is my MyServiceFault [DataContract] public class MyServiceFault { [DataMember] public

Exception handling in a three-tier Asp.Net application

拜拜、爱过 提交于 2019-12-21 21:19:01
问题 1) To my understanding, in a three-tier Asp.Net application we should implement exception handling in the following way: a - we should put try-catch block around block of code ( located in any of the three layers ) from which we expect the page to gracefully recover from ( when this code generates an exception )? b - we shouldn’t put try-catch blocks around code ( located in either of the three layers ) from which we don’t expect the page to gracefully recover from. Instead, Asp.Net

Selenium occasional UnreachableBrowserException

浪尽此生 提交于 2019-12-21 21:03:15
问题 I am trying to access several websites by using Selenium in Java. Occasionally, I get an UnreachableBrowserException . I have read many threads about this error but it seems like there are many different causes of the error. I get the error about 1% of the time when I attempt to access a new page and I cannot find any similarities between occurrences. I currently am using Firefox, however I have also tried Internet Explorer and experienced similar errors. I am only opening one page at a time

Java compiler complaining about unreported IOException

这一生的挚爱 提交于 2019-12-21 20:44:12
问题 I'm trying to write a method that lists all non-hidden files in a directory. However, when I add the condition !Files.isHidden(filePath) my code won't compile, and the compiler returns the following error: java.lang.RuntimeException: Uncompilable source code - unreported exception java.io.IOException; must be caught or declared to be thrown I tried to catch the IOException , but the compiler still refuses to compile my code. Is there something glaringly obvious that I'm missing? Code is

Some sort of Ruby “Interrupt”

前提是你 提交于 2019-12-21 18:32:32
问题 So here's what I'm doing -- I have a ruby script that prints out information every minute. I've also set up a proc for a trap so that when the user hits ctrl-c, the process aborts. The code looks something like this: switch = true Signal.trap("SIGINT") do switch = false end lastTime = Time.now while switch do if Time.now.min > lastTime.min then puts "A minute has gone by!" end end Now the code itself is valid and runs well, but it does a lot of useless work checking the value of switch as

Catching EngineExecutionException

左心房为你撑大大i 提交于 2019-12-21 17:51:47
问题 I have an application containing both managed and native code. The application currently has an unhandled exception filter, set via SetUnhandledExceptionFilter, which catches any critical errors, generates a minidump, records various application parameters, and exits the program. The unhandled exception handler does not catch an EngineExecutionException which occurs in the .NET runtime. We suspect the problem is memory corruption caused by the native portion of the application. The problem is

How to deal with “MemoryError” in Python code

孤者浪人 提交于 2019-12-21 17:29:35
问题 I have some piece of python code which generates a MemoryError after a while. I know that it consumes a lot of memory. So, I decided to put the code within a try/except block so that the skeleton looks like the following: while True: while True: try: #---- do some stuff except MemoryError as err: print(err) break So, my idea is to break out of the first while -loop if a MemoryError occurs and since I have an outer while -loop, it will start the program again. It seems that it works for the

Why Java’s exception-handling statements should not be considered a general mechanism for nonlocal branching?

一曲冷凌霜 提交于 2019-12-21 17:25:18
问题 Going through Herbert Schildt : The Complete Reference Chapter 10 Exception Handling Exception handling provides a powerful mechanism for controlling complex programs that have many dynamic run-time characteristics. It is important to think of try, throw, and catch as clean ways to handle errors and unusual boundary conditions in your program’s logic. Unlike some other languages in which error return codes are used to indicate failure, Java uses exceptions. Thus, when a method can fail, have

ArrayIndexOutOfBoundsException not being caught and ignored

▼魔方 西西 提交于 2019-12-21 16:21:00
问题 I want to catch and ignore and ArrayIndexOutOfBoundsException error (basically it's not something I have control over, so I need my program to keep chugging along). However my try/catch pair doesn't seem to catch the exception and ignore it. Hopefully you can pick out what I am doing wrong. The exception occurs at this line content = extractor.getTextFromPage(page); Here is my code: for(int page=1;page<=noPages;page++){ try{ System.out.println(page); content = extractor.getTextFromPage(page);

How to detect System.IO.IOException cause by existing file?

白昼怎懂夜的黑 提交于 2019-12-21 16:17:39
问题 I want to create and open a file but only if it doesnt exist. I dont want to use a File.Exists because a thread by switch after it creating a file with the same name. How do i check if the exception System.IO.IOException was caused by the file existing? I prefer not to parse the error msg (even tho it can be as simple as .indexOf("exist")) How should i do this? 回答1: You should avoid ever making logic decisions based on the contents of the Exception.Message property. That is defined to be a