Click here to Skip to main content
15,915,093 members
Everything / Error handling

Error handling

error-handling

Great Reads

by Greg Utas
No breakpoints or drooling all over the console!
by Aleksandrs Vorobjovs
Error Logging to the Windows Event Log using ELMAH
by freedeveloper
The move of the WEB from server based pages to Client based pages can create a security problem if we don't modify our traditional form to report errors.
by ChristianNeumanns
Error-handling is important, but nobody wants to do it!

Latest Articles

by ChristianNeumanns
Error-handling is important, but nobody wants to do it!
by Greg Utas
Keeping a program running when it would otherwise abort
by Greg Utas
No breakpoints or drooling all over the console!
by Brien King
Error messages and why they are important

All Articles

Sort by Score

Error handling 

10 Mar 2022 by Greg Utas
No breakpoints or drooling all over the console!
5 Mar 2012 by Aleksandrs Vorobjovs
Error Logging to the Windows Event Log using ELMAH
26 Jan 2014 by phil.o
Clearly your are using Windows Forms. So in this context there is no Response object, which you can only find in web applications.So you have several choices :1- Create a web application instead of a Windows Forms one2- Create a console application and useConsole.Write("Whatever...
22 Jun 2021 by freedeveloper
The move of the WEB from server based pages to Client based pages can create a security problem if we don't modify our traditional form to report errors.
8 Jul 2011 by fjdiewornncalwe
For starters, why are you using a timer for a manual process that should be handled by the KeyPress event instead.Secondly, we can't really give you a lot of other help if you don't tell us what the exception itself is. We aren't mind readers, you know... Cheers.
8 Jul 2011 by Sergey Alexandrovich Kryukov
All wrong!Throw out this code and never do anything similar. Don't poll keyboard using timer, use keyboard input events provided by .NET. In general, avoid using timers; use threads whenever possible instead of timers.Don't use Thread.Spleep for waiting for some condition or without...
28 Jul 2011 by Monjurul Habib
http://blogs.m...
19 Jul 2013 by Sergey Alexandrovich Kryukov
In addition to the Solution 1:One ultimate requirement to handling exceptions: catch them all on the top stack frame of each thread. Event-oriented UI threads have their own twist: all exceptions should be caught in the main even cycle of the thread. Usually, UI libraries have the special...
13 May 2015 by Afzaal Ahmad Zeeshan
The main exception (HttpUnhandledException) would never give you a very good message of what the problem is. The problem in this context is in the inner message. Inner message states, Quote:Input string was not in a correct format.So, the solution is that you are not providing a string...
20 Mar 2017 by Jochen Arndt
The error is here:m_message = new char[strlen(value + 1)];That will allocate two characters less than required (random size when the passed string is empty).It must be:m_message = new char[strlen(value) + 1];The error is also present with G++ builds but not detected.
20 Jun 2018 by F-ES Sitecore
try { // your code here } catch(Exception exp) { // you can log the exception here or simply do nothing } finally { // the finally block is optional but you can put code you want to happen here after an exception occurs if you want } That answers your question but it isn't going to...
28 May 2020 by phil.o
Why ignoring the success for the last step? You could try either newTask.Priority = ReadPriority(out success); return newTask; // ignoring success status or newTask.Priority = ReadPriority(out success); if (!success) return null; return...
15 Nov 2021 by CHill60
The VB6 error handling you have shared is not very good at all FileOpen is a likely point of failure so should be surrounded by a Try-Catch. As you are reading lines from the file should validate that the data is or is not present and code...
6 Apr 2011 by Slacker007
In your line:If c Is Nothing Then Exit SubYou are exiting the sub routine without handling the blank variable for the input box. Write and "If" statement that tests the contents of the variable "c" and handle the test accordingly.I don't like to use the following line unless I...
11 Apr 2011 by vaishnavirs
I am trying to run a Word Web application in a tab control but unable to do it. I have pasted my code for your kind reference.Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged If...
11 Apr 2011 by Sergey Alexandrovich Kryukov
This is what it is. The exception message is self-explanatory. You always need to comment exact like of code where it is thrown when asking your Question though.You start some process, it starts and finishes, but you still have the instance of the Process PR. You assume the process is still...
26 Apr 2011 by Abhinav S
If you want to log every error, you might want to look at more advance tools like Log4Net.
26 Apr 2011 by Sandeep Mewara
For log4Net:How to use log4net[^]Log4Net Tutorial in C# .net [^]If needed, look here[^] for more.For Microsoft Enterprise Library - Logging Application block:Introduction to the Logging Application Block[^]Getting started with the Logging Application Block[^]While...
28 Jul 2011 by #realJSOP
Try using this:string url = Request.RawUrl;If you want the physical file path:string path = new Uri(Request.RawUrl).Absolute.Path;
16 May 2012 by member60
If you are using try catch in your code ,add the following statementthrow ex;to the catch blockif you suppress the exception you will not be redirected hence simply throw the exception.
25 Apr 2013 by Bernhard Hiller
Use your own Exceptions. Create appropriate exception classes inheriting from System.Exception or System.ApplicationException or other, and add your ErrorCode property. Thrown the exception when appropriate in the Business Layer. In the Presentation Layer, you need some try...catch blocks, and...
8 May 2013 by Jochen Arndt
The error message indicates stack problems around threadno. And it is really helpful here when looking at the occurences for that variable:char threadno[2];itoa(threadNumber,threadno,10);strcat(threadno,".txt");Did you see the problem? The string can hold only one character plus NULL...
8 May 2013 by CPallini
You didn't bother to close the file, did you?Call fclose(fpSend); when you've done with it (before returning from the WndProc).
19 Jul 2013 by Ron Beyer
I would fail with a generic error then write detailed failure info to the application log or an error reporting file. Best practice for handling exceptions is to only handle exceptions that you can do something about it, the rest you pass up the call stack (aka, don't catch them). You can...
4 Aug 2013 by CHill60
Personally I hold the view that you should handle exceptions at the earliest opportunity - i.e. not at the application level.I found this article today which I would recommend reading Exception Handling Best Practices in .NET[^]However, you can still capture unhandled exceptions at the...
2 Apr 2015 by Peter Leow
addPreferencesFromResource(int id) had been deprecated, try PreferenceActivity[^] instead. It has a sample code.
11 Jan 2017 by ZurdoDev
You are declaring a variable in the middle of the if/else if structure. int answer02 = Convert.ToInt32(Console.ReadLine()); is in the wrong spot.if (){}// you cannot put code here.else if (){}
11 Jan 2017 by Thomas Daniels
The problem is your else if statement after your answer02 declaration. An else if statement always has to follow an if statement immediately, which is not the case here because the answer02 declaration is in between.There are two things that you can do to fix the error, and you'll have to...
11 Apr 2017 by Richard Deeming
If you're using C# 6 (Visual Studio 2015 or later), you can use an exception filter: catch (WebException we) when (we.InnerException is SocketException) { var se = (SocketException)we.InnerException; if (se.SocketErrorCode == SocketError.TimedOut) { ... } } catch...
19 Jun 2017 by Member 9983063
Hello Guys, How are you, I hope you will be fine well I have another issue in my project last night I have code from Google to save image in directory folder with picture box but when I add the same pic in this folder soi get an error filename already exist I wanna overwrite image if image is...
4 Jul 2017 by OriginalGriff
Don't convert the date to a string to pass it to SQL: if it's a DateTime value already, pass it as such. If not, use TryParse to convert it to a DateTime, and then pass that. The trouble with string dates is that they aren't the same for all systems: the locale for an SQL Server instance can be...
20 Jun 2018 by OriginalGriff
As F-ES Sitecore says, catching the exception is simple. But ... it's a very bad idea. You get the exception because something is wrong, and the process can't continue. Catching the exception is there to let your code recover gracefully from a problem, it doesn't solve the problem. I have no...
26 Nov 2018 by Patrice T
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone. A single quote in a name and your program crash. If a user input a name like...
17 Feb 2019 by Bryian Tan
That case, you can update the code to check for type if not type(room) is int: to print out the exception, try import sys except: print("Unexpected error:", sys.exc_info()[0]) Example: CP_hotel | Pyfiddle[^] error handling - How to print an exception in Python? - Stack...
7 Aug 2020 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a...
12 Dec 2020 by Shao Voon Wong
You create a Windows project instead of a Console project. Windows application starts from WinMain() while console application starts from main(). Yours is a console application. You have 2 options to fix it: either recreate a new console...
18 Dec 2020 by Patrice T
Not your question, but still a problem you have: Beware of division of integers # when I see this, I suspect unwanted behavior -(x1-x1_star)*G*m/((x1-x1_star)**2+(x2-x2_star)**2+(x3-x3_star)**2)**(3/2) print (3/2) # gives 1 print (3.0/2) #...
25 Jun 2021 by Patrice T
What happens to $query when $_SESSION['user_role'] is neither '1' or '0' ? if($_SESSION['user_role']=='1'){ $query="SELECT post.post_id, post.title, post.description, post.post_date, category.category_name,user.username FROM post ...
17 Mar 2022 by Richard MacCutchan
You need to learn about the scope of variables. if(isset($_GET['pr_id'])){ $id = $_GET['pr_id']; // $id only exists within the scope of this block } // $id no longer exists here $sql = "SELECT * FROM product WHERE...
10 May 2022 by Patrice T
Quote: if we assign string to integer it is easy that detect our error, but runtime it is difficult. May be time to break the debugger. Your code do not behave the way you expect, or you don't understand why ! There is an almost universal...
10 May 2022 by Greg Utas
You tagged this as a Java question. Java is typed, so assigning a string to an integer isn't possible. Most software errors are logic errors. The software isn't doing anything illegal. It's just not doing what you intended, but there's no way to...
27 Jun 2022 by steveb
*ptr is dereferencing. Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being...
9 Sep 2022 by Chris Copeland
You've managed to correct the issue where you were comparing the wrong thing: this.restaurantList.filter((item) => {return item.city==givencity}) This is correct, you should be looking at the city property. Now, if you're saying your console is...
4 Mar 2023 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a...
1 Mar 2024 by ChristianNeumanns
Error-handling is important, but nobody wants to do it!
N 9 Jun 2024 by Pete O'Hanlon
If memory serves me correctly, when you are deploying a Vercel app, you need to specify the CORS configuration inside the vercel.json file. Vercel overrides the settings in Express because you can think of it as acting as the Gateway here. In...
12 Apr 2011 by Sweetu deshpande
How to solve following error?sys.webforms.pagerequestmanagerservererrorexception:an unknown error occurred while requesting to server. the status code return from the server was:502I cant remove the UpdatePanel from this page. As I observed this error, it is occurring on one or two computers...
12 Apr 2011 by thatraja
The below one will resolve your issue.Sys.Webforms.PageRequestManagerServerErrorException actual cause[^]Free attachmentHTTP Response Status Codes[^]
12 Apr 2011 by Monjurul Habib
How to: Specify a Port for the ASP.NET Development Server Apache, IIS and 502 proxy errorWeb Servers in Visual Web Developer Troubleshooting the ASP.NET Development ServerASP.NET Development Server cannot be accessed using non-localhost URLIf i misunderstand your question, please...
26 Apr 2011 by kia.sos
HiAs you know the basic method for handle error is try ... catch ... finally structure.If we want to handle every error and save it into a file, we have to add one line to catch section for save error details.The question is:Is there any solution for override catch event?In...
26 Apr 2011 by Olivier Levrey
What you want is not possible (as far as I know).All you can do is trapping the uncought exceptions: static class Program { [STAThread] static void Main() { ... //Exceptions from main thread ...
26 Apr 2011 by tnd2000
See here http://msdn.microsoft.com/en-us/library/ms733025.aspx[^] where it states all exceptions are logged if trace level is set to error. The only way I know of to handle your 'override catch problem' in code is to rethrow the error from the catch so that your global error handler can...
17 May 2011 by OriginalGriff
Depending on what your stored procedure returns - and I haven't a clue - I think you have confused the error reporting.Rather than just blindly using Convert.ToInt32, try checking what type it is returning and cast it appropriately before attempting to convert.
17 May 2011 by Ankur\m/
Did you search for the error message?Here is the Google search link - similar discussions[^].
17 May 2011 by Pete O'Hanlon
I don't think this is the right function. The error is telling you that there's a mapping issue between a ListItem and a SQL data type - this function doesn't have any ListItem's in it (assuming that you aren't doing anything daft with your naming conventions). The error output should...
17 May 2011 by gowthammanju
I use the following code for sending a FAX: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack){ FaxDocument(@"E:\ss.doc", "04428257363"); } } public int FaxDocument(String TheFile, string faxnumber){int JobID = 0; FAXCOMEXLib.FaxServer faxsrv = new...
18 Mar 2022 by Ahiri
Hi,I want to pass the byte array into insert query but I am not using the parameter. I am directly passing values into insert query.I am getting the following error:at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response,...
23 May 2011 by reid0588
Hii am having an issue with closing the connection to my sql server when an error occursmy program allows a user to upload an excel file with specific format and a specfific tab name, as this is the template sent out the the client, however as we all know not everyone will use the template...
24 May 2011 by reid0588
hi so ive figured out how to close the connection using alert boxes wooo hoobut now the issue i am having is that when the excel file is uploaded, but the tab name is wrong the error alert box i not displayed, however if the uploaded file is in the incorrect format (e.g the title of the...
2 Jun 2011 by gowthammanju
Ya, i got the solution asprotected void GridView1_DeleteCommand(object source, DataGridCommandEventArgs e){ int indx = e.Item.ItemIndex; lbl_id.Text = GridView1.Items[indx].Cells[1].Text; //Change the cell name based on the primary key of the table, }delete from Fax_tablename...
16 Jun 2011 by Girish Jawale
I received the error below while I was trying to run my application on locally hosted azure. This error pops up with the title "Microsoft Window Azure Web Host"Problem Event Name : APPCRASH Application Name : WaWebHost.exeFault Module Name : KERNELBASE.dllHow can I resolve this...
21 Jun 2011 by Karwa_Vivek
I suggest you to Use ToolTip and ErrorProvider.for this Check This link[^]or you can try this CodeProject article [^]to get your job done
21 Jun 2011 by Reuel.Lawrence
Damn I feel like a noob. I didn't realise you could use the Error Provider on more than one control!!I created two Error Providers - one for missing fields and one for format errors, gave them their own spiffy icons and it works like a charm.Thanks so much!
24 Jun 2011 by Member 8015046
Hi I am trying to deploy a website to iis. And I accidentally deleted the default web site. So I did the steps to bring back the default web site back into iis. It keeps telling me to check if some id thing is 1. which it is. It gives me this...
24 Jun 2011 by thatraja
Here you goCould Not Load Type 'xxxxxxx.xxx.UI.Admin.Test' - ASP.NET 2.0 Error and Solutions[^]Also make sure the referred file(which is in error) in that system.
28 Jul 2011 by Manas Bhardwaj
string errorSourcePage = HttpContext.Current.Request.Url.ToString();
31 Jul 2011 by OriginalGriff
The clue is probably in the error message "E_ACCESSDENIED"You have presumably been denied access to a file, folder or share on the server, and this is the result. Check y=with your server admin to find out why, or check your access manually before you run the app.
31 Jul 2011 by Karan_TN
Hi all,Currently i m using asp.net with c# 2008 (SQL Server 2008). i m uploading an excel file to server and loading the same data to gridview. past few months everything working fine. suddenly the error No error message available, result code: E_ACCESSDENIED(0x80070005) is occuring. That...
4 Aug 2011 by prathameshpitale
Hi,My Application is Designed in c#.net 3.5,I want to Handle Unhandled Exceptions occured while running the application!How can i do this? I Googled this Question but cant find answer!How can i collect the Log of Errors, As my Application is Client Server, I need to Collect ALl the...
22 Sep 2011 by Armando de la Torre
Use an error log control to validate forms.
3 Nov 2011 by Member 7791974
Hi all, im having mad problems here...i have a datagrid that i have added two new columns of unbound data. I want to make it work so that it displays given name and last name in a table that only has ID and other information so that the viewer knows what information belongs to who. this is the...
3 Nov 2011 by Tejas Vaishnav
For your solution of your error please do this...1) put a break point of your line at this... DataRow findRow = data.Tables["People"].Rows.Find(personID);and press F10 then browse your findRow object if it will contain some thing or not...then user immediate solution window and...
4 Nov 2011 by Member 7791974
Thank you Tejas!The issue was thatint personID = Convert.ToInt16(selectedRow.Cells[0].Value);was looking for stuff in the first column. What it was meant to be doing is looking in the number column where the ID was. so if id was in the third column then the selected row cells value...
10 Dec 2011 by thatraja
Fix linksMore Azure run and deployment problems[^]ASPProvider from azure samples throws configuration error when deployed to Azure[^]
15 Mar 2012 by Mohammed Dawood Ansari
I don't why suddenly my project is getting an errorError 1 The item "obj\Debug\MDI.frmChangePassword.resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter. MDII am not able to understand this error, I tried...
15 Mar 2012 by Richard MacCutchan
This[^] looks like the same problem.
15 Mar 2012 by Sergey Alexandrovich Kryukov
I would advise to open a project file as text in a regular text editor and search for "MDI.frmChangePassword.resources". Does it appear twice? If so, remove redundant node (backup the file before this experiment, of course).I vaguely remember such cases appeared after tricky but incorrect...
29 Apr 2012 by Member 8885701
How do you modify code so that it will not crash if the database server is unavailable when you attempt to access it? If this happens then there must be an appropriate way to handle the error. I do not know where to put the Try..Catch procedure.Protected Sub Page_Load(ByVal sender As...
29 Apr 2012 by satrio_budidharmawan
Use error handling such as try...catchSimply just do thistry catch (e as exception) msgbox("Error happened at "+e.toString())end try
29 Apr 2012 by Sandeep Mewara
You wrap try-catch around the code that has potential of getting an error. Here, in your code the line that tries to connect to DB and get back data is one of those places where probability of having an error is high. Wrap your try-catch around the following line:l = db.GetCustomersForLookup
16 May 2012 by Sandeep Mewara
This problem occurs because the handler mapping for the requested resource points to a .dll file that cannot process the request. To resolve this problem:Edit the handler mapping for the requested resource to point to the .dll file that can process the request. To do this, follow these...
10 Jul 2012 by sudhakar_dasoju
Take a backup of the file(copy both .cs and .designer.cs file) which is giving the error and then delete that file from the project. After removing the problem file rebuild the solution and then add the same file back (add both .cs and .designer.cs file) and again rebuild the solution back.
28 Aug 2012 by Naga KOTA
hi,In the following connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"providerName="System.Data.SqlClient" />try to provide the followingDataSource=./localhost/ipaddressUser...
8 Oct 2012 by Varun Sareen
Dear Friend,With the help of ajax it is very simple to error handle the kind of errors you are looking to handle.Include the Ajax handle class into your code file may it be C# or VB.Net and then try to put all the methods under the Ajax class (with TRY{} CATCH(){} handler) for which you...
28 Oct 2012 by Ed Gepulle
after amending the code i received this error:Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.
28 Oct 2012 by Ed Gepulle
Thanks for your help it works!
9 Nov 2012 by Sergey Alexandrovich Kryukov
From the first glance: in the class ConwayModels, ConwayController field is private, declared but never used. It is never initialized (with "new").—SA
9 Nov 2012 by Member 9561202
Cyclical dependence on a Contoller. Model and View do not know about real Conroller, only Interface Controller. The model and view shan't be crossed. Thanks to all.
18 Nov 2012 by kk2014
hi all,how do i get error code from catch (Exception ex), say i got error "The request failed. The remote server returned an error: (401) Unauthorized."i want error code 401 only.thanks,krunal
18 Nov 2012 by MT_
You can try to catch WebException.catch (WebException ex){ HttpWebResponse resp = (HttpWebResponse)ex.Response; if (resp!= null) { int httpCode = (int)response.StatusCode; }}Hope that helps. if it does, mark it as answer/upvote.ThanksMilind
26 Dec 2012 by Ganfun kama
Hi We have a website completely in classic asp, where our client asked us to move on with SSL so went for thwate 123 256 SSl certificate. Before the SSL was installed on the server, everything was working fine but just after the SSL we started encountering issue with file upload and in...
24 Feb 2013 by nature_140
Hai Techie1. while running this code it shows an try{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Iwens_Database;Integrated Security=True");SqlCommand command = new SqlCommand("SELECT E_id, E_Name, E_Address, E_Contact_No, E_Email, DOEn, E_noi, E_coursename,...
24 Feb 2013 by maxrockM
It is not able to connect to the Database properly.Provide proper values to DataSource and Provide User Id and Pwd and try.Below link to know about Connection Strings:connectionstrings
7 Mar 2013 by criselda
We have a website completely in classic asp, where our client asked us to move on with SSL so went for thwate 123 256 SSl certificate.Before the SSL was installed on the server, everything was working fine but just after the SSL we started encountering issue with file upload and in binary...
7 Mar 2013 by criselda
We have a website completely in classic asp, where our client asked us to move on with SSL so went for thwate 123 256 SSl certificate.Before the SSL was installed on the server, everything was working fine but just after the SSL we started encountering issue with file upload and in binary...
25 Apr 2013 by ravithejag
Hi,In my application when exception occurs i need to pass the Error Code from the Business Layerto the Presentation layer here based on the error code i need to show the message that is available in the DB.I want to know how to pass and get the Error code in the Presentation Layer.For...
29 Apr 2013 by ravithejag
How to fetch he values from extended propertiestry { // ... } catch (Exception ex) { ex.Data.Add("Hello", "World"); throw ex; }The exception is logged correctly, but I can’t find the added data anywhere in the log file.
29 Apr 2013 by ravithejag
it worksforeach (DictionaryEntry item in ex.Data) { string exceptionData = item.Key +" "+ item.Value; }
15 May 2013 by Mohammed Hameed
Hey!!!I hope that Exception Handling approach (as proposed by Microsoft's Guidelines & Best Practises) will not have any deviations (or impact) according to any domain specfic or because of client requirements.Having said that could anybody help me to justify whether catching main...
8 May 2013 by ayesha hassan
My following code gives an error "Run-Time Check Failure # 2 - Stack around variable 'thread no' was corrupted." if I add a "break" inside my if statement. I have also hghlighted this "break" inside the code. If I remove thi "break", the error is removed.Can anyone explain me please why does...