exception-handling

The transaction must be disposed before the connection can be used to execute sql statements

你说的曾经没有我的故事 提交于 2019-12-10 17:00:04
问题 I am getting this error The transaction must be disposed before the connection can be used to execute sql statements. i have an Excel file that contains about 6000 rows and I uploaded these file into Data table in typed dataset, then I am trying to apply my business logic on these rows in dt. The exception throws from the second loop and I have to do two loops; why does this exception occur, and how can I solve it? Here is my code: try { using (TransactionScope scope = SysInfo

Difference between Exception and SQLException

拟墨画扇 提交于 2019-12-10 16:58:36
问题 Can someone explain the difference between catching an Exception and catching an SQLException ? I know that SQLException will print out more information if you choose to print out the exception errors, but is there anything else? try { //code } catch(Exception ex) { //code } And try { //code } catch(SQLException ex) { //code } What are the benefits and differences of using Exception and SQLException in the catch block? 回答1: This is not the only difference. Catching Exception is dangerous

Getting reference to original Task after ordering Tasks by completion?

南楼画角 提交于 2019-12-10 16:46:03
问题 I asked a question a while ago about a method that orders a List<Task<T>>> by their completion that also returns an int representing the index of the completed Task in the original List<Task<T>> given. I have the inkling that I might not need to return this int to determine which specific Task has completed and that I can interrogate the returned Task for this information. As a side note, I have since altered the method to order a List<Task> . I originally used Task<T> , which returned a bool

how to catch a NoSuchElementException?

懵懂的女人 提交于 2019-12-10 16:30:10
问题 My class assignment is to write a program that has the user input a set of numerical values. If the user enters a value that is not a number, the program is supposed to give the user 2 second chances to enter a number correctly, and after those two chances, quit asking for input and print the sum of all values entered correctly so far. As is, my code doesn't work quite right. When the first non-number is entered, the program executes the code in the catch block once, prints the "gimme input"

How and where do we write try catch block to handle Exception

佐手、 提交于 2019-12-10 16:05:10
问题 We are using C# language to develope a Windows application. Our windows application consists of three layers (UI,Business and DataAccess layer). In Business Layer there are some public (business) methods through which UI communicates wilh Business layer classes. These public methods also have some private methods to implement the required functionality. There are some methods in DataAcess layer which are called from Business layer class. In this situatuion where should i wrte try-catch? a) In

When should we throw exceptions, or catch exceptions, in a method?

我只是一个虾纸丫 提交于 2019-12-10 15:59:52
问题 I've been reading up more on exceptions, but I am not sure with what cases we should either throw a method public void fxml() throws IOException { // method body here } or catch an exception within a method public void fxml() { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml.fxml")); try { fxmlLoader.load(); } catch (IOException exception) { throw new RuntimeException(exception); } } From Oracle's example it says Sometimes, it's appropriate for code to catch exceptions

Is Try/Catch ever LESS expensive than a hash lookup?

强颜欢笑 提交于 2019-12-10 15:55:26
问题 I'm aware that exception trapping can be expensive, but I'm wondering if there are cases when it's actually less expensive than a lookup? For example, if I have a large dictionary, I could either test for the existence of a key: If MyDictionary.ContainsKey(MyKey) Then _ MyValue = MyDictionary(MyKey) ' This is 2 lookups just to get the value. Or, I could catch an exception: Try MyValue = MyDictionary(MyKey) ' Only doing 1 lookup now. Catch(e As Exception) ' Didn't find it. End Try Is exception

Structured exception handling with a multi-threaded server

我是研究僧i 提交于 2019-12-10 15:52:14
问题 This article gives a good overview on why structured exception handling is bad. Is there a way to get the robustness of stopping your server from crashing, while getting past the problems mentioned in the article? I have a server software that runs about 400 connected users concurrently. But if there is a crash all 400 users are affected. We added structured exception handling and enjoyed the results for a while, but eventually had to remove it because of some crashes causing the whole server

Assigning a value in exception handling in R

て烟熏妆下的殇ゞ 提交于 2019-12-10 15:48:56
问题 while(bo!=10){ x = tryCatch(getURLContent(Site, verbose = F, curl = handle), error = function(e) { cat("ERROR1: ", e$message, "\n") Sys.sleep(1) print("reconntecting...") bo <- bo+1 print(bo) }) print(bo) if(bo==0) bo=10 } I wanted to try reconnecting each second after the connection failed. But the new assignment of the bo value is not effective. How can i do that? Or if you know how to reconnect using RCurl options (I really didn't find a thing) it would be amazing. Every help is

Detect 404 without catching exceptions

给你一囗甜甜゛ 提交于 2019-12-10 15:39:19
问题 Simple function: Check if a webserver returns a non-200 HTTP status. Private Function RemoteFileOk(ByVal Url As String) As Boolean Dim req As HttpWebRequest = TryCast(WebRequest.Create(Url), HttpWebRequest) req.Method = "HEAD" Dim rsp As HttpWebResponse = TryCast(req.GetResponse(), HttpWebResponse) Return (rsp.StatusCode = HttpStatusCode.OK) End Function I got it from this answer on "How to check if a file exits on an webserver by its URL?". Unfortunately, it doesn't work: A System.Net