Click here to Skip to main content
15,891,597 members
Everything / General Programming / Exceptions

Exceptions

exceptions

Great Reads

by Giovanni Scerra
Patterns to prevent null reference exceptions
by Jasper Lammers
A method to easily toggle the way exceptions are being handled (either being thrown or handled by custom code), while still conserving the stack trace when exceptions are not being thrown.
by Marco Bertschi
This tip presents an easy way of verbosely converting an exception and its inner exceptions to a string in order to get access to all details.
by Amogh Natu
This tip provides one solution to the exception "Configuration system failed to initialize" in C#

Latest Articles

by Dev Leader
Secret of Task EventHandlers
by Bruno van Dooren
Symantec can cause valid applications to crash and be gone without a trace
by Mark Pelf
We explain how to debug and get more information on the generic Exception “Failed to enable constraints.
by Greg Utas
Keeping a program running when it would otherwise abort

All Articles

Sort by Title

Exceptions 

15 Apr 2015 by Aswin_kumar
Hello,I am trying to connect to the Database from the application and its not happening at all. The same DLL is working fine in QA and production.When debugging I understood the SQL connection is always closed.when I checked the below line of code,public static SqlConnection...
14 Apr 2015 by vgandu
Can you verify your connection string is correct, also make sure before calling ExecuteReader you open the DB connection.
25 Nov 2013 by Cenkay Vergili
SmoException was unhandled,An unhandled exception of type 'Microsoft.SqlServer.Management.Smo.SmoException' occurred in Microsoft.SqlServer.SmoExtended.dllAdditional information: The Integration Services component is not installed or you do not have permission to use it. Server...
25 Nov 2013 by thatraja
Based on the error message & additional information, I got a thread, check it out.http://social.msdn.microsoft.com/Forums/sqlserver/en-US/479651b7-e838-4d4d-b298-02cf791ced57/the-integration-services?forum=sqlsmoanddmo[^]
6 Sep 2012 by cple82309
I have a small .bat program that runs at night using VB.NET 4.0. The job use to run on a Window XP Service Pack 3. I tried to migrate the application to a Windows 2003 Service 3. The application failed stating System.Null exception. I followed the code and it seems to fail on initializing...
6 Sep 2012 by Dave Kreskowiak
I'll assume that "SystemNull exception" actually means "Object not set to an instance of an object".All you have to do is step through the code where it bombs and check to see which one of your objects returned Nothing. Your code is making the assumption that some call that is supposed to...
30 Jan 2020 by Oleg Pruh
Hi, I work in Unity 2018.4.16f1 (64-bit). Today I had to build my project in Grudle, but there is a problem. Help me as soon as possible. Please do not write much, but to understand, you can write a solution step by step. 1 exception was raised by workers: See the Console for details. ...
30 Jan 2020 by Richard MacCutchan
java.lang.RuntimeException: Duplicate class com.unity3d.ads.BuildConfig found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.IUnityAdsListener found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class...
19 Jan 2015 by JatinKhimani
Develop a web application in 3 layer architecture code style
15 Jan 2017 by Member 12951338
I do not know what is causing this problem. I have 2 forms (Search form & Accounts form) in Accounts Form there is a Search button which opens the Search. Code for opening the search form:private void btnSearch_Click(object sender, EventArgs e) { SearchForm sf = new...
15 Jan 2017 by Dave Kreskowiak
Googling this isn't going to give you any answers. You MUST use the debugger on this code and find the variable that is null when the exception is thrown. Then go backwards through the code and find out why the variable contains null.We can't do this for you. We can't run the code and we...
15 Jan 2017 by Wendelius
As far as I can see, when you create the SearchForm, you call the default constructor, not the one with account form defined as parameter. Later in the code you try to use the variable rf, which is null because you used the wrong constructor.If the btnSearch is located on the account form,...
19 Apr 2011 by WY Lee
Hi,I have a question about StackTrace.I am using "Embarcadero c++ builder 2010".I have failed to use StackTrace of Exception class.The StackTrace property always gives me NULL.I want to see call stack while run time.Please sombody help me.Below is the test code.The "st" is...
19 Apr 2011 by Sergey Alexandrovich Kryukov
Must be:void TestFunc(int c){ try { int test = 0; test = test/test; //throw exception here; } catch (Exception ^ e) { String msg = e->Message; String st = e->StackTrace; //... }}This System::Exception property is just a human-readable...
1 Apr 2017 by Marco Bertschi
This tip presents an easy way of verbosely converting an exception and its inner exceptions to a string in order to get access to all details.
17 Jan 2013 by David Serrano Martínez
A strong exception guarantee tester has been written to test how robust methods of class templates are when faced with third party exceptions.
11 Jul 2014 by Regaloq
Hi,I have a problem. I have a project based multi-thread. All threads have webbrowser control.The project works fine on single thread. But when i am trying to work on multi-thread, i get AccessViolationException. There is "document.GetElementById();" expression on line of exception thrown....
11 Jul 2014 by Dave Kreskowiak
You cannot use nor create instances of the webbrowser control on any thread other than the UI (startup) thread.You also cannot touch, in any way at all, any control on a form from anything other than the UI thread.If you must set properties and call methods on UI controls from other...
20 Aug 2011 by cybfly
Thanks for your amazing job,but i have a question in using this popup.Just like the demo when i run this demo i found it shows well in chrome but did not work in IE6.I am using vs2008 and win7, and i do not know why.Each button each page i tried gives me the same answer, so i want to know...
20 Aug 2011 by Abhinav S
Try posting this in the article you are referring to.The author will be able to answer this quicker that way.Incidentally, you have not put a link to the article here, so no one knows which article you are talking about.
26 Jun 2012 by chanu_babu
Hi,I have control bitmap data using unsafe code,which is working perfectly in 2008 whereas the same code is raising memory access violation exception when run in vs 2010.The code is as below:Bitmap canvas = new Bitmap(pictureWater.Width, pictureWater.Height);BitmapData data =...
2 Jul 2012 by chanu_babu
yes, i have tried ImageLockMode.ReadWrite too, but still no use..and width = canvas.Width;
3 Jul 2012 by Fun@learn
Instead of byte* pixel = (byte*)data.Scan0.ToPointer();usebyte* pixel = (byte*)data.Scan0;Refer this link[^] for bitmap read write operaton.
7 Dec 2011 by Anoop_Ravindran
Hi all,I have a .net 4.0 windows application which is migrated from .net 3.5. This windows application is using a third party DLL file (from Windows\system32\MyScanner.dll) which is used to connect with a scanner attached to the system through USB port. This application is working...
7 Dec 2011 by Richard MacCutchan
There is no general resolution to this problem. The first thing you need to do is to discover where in the program the error is occurring and why, and then try and fix it. If the error is in the DLL then you need to go back to the suppliers and get some diagnosis from them.
9 Nov 2011 by Himu from Orissa
i m using sql connection i get the the error while i m executing the following code.SqlCommand cmd = new SqlCommand();cmd.CommandText = "insert into ticket values(@pnrno,@tno,@seat)";cmd.Connection = conn;cmd.Parameters.Add(new SqlParameter("@pnrno",...
9 Nov 2011 by Prerak Patel
Close the reader. if (clas == "firstac") { string query = "select firstac from vacseat where tno='" + tno + "'"; SqlCommand cmd2 = new SqlCommand(query, conn); SqlDataReader dr = cmd2.ExecuteReader(); if (dr.Read()) { seat = int.Parse(dr["firstac"].ToString()); }...
14 Oct 2021 by HIMANSHU SRIVASTAVA Oct2021
```This register servlet class from where the exception is generating``` *Earlier the code was running fine on inputting fields in the page.But,after sometime it is generating this exception* package com.techblog.servlets; ...
14 Mar 2011 by mohit`12
I am getting this error on client computer while trying to access database through grid.I have hosted an website on localhost with simple SQL database. and when i try to access database it seems to be working fine.CODE:clientconfig: ...
15 Mar 2011 by Sergey Alexandrovich Kryukov
Answering to the reply about exception:Here is the advice what to start with. The problem is that you don't provide enough information about exception. Please see my directions:How do i make a loop that will stop when a scrollbar reaches the bottom[^]When i run an application an...
15 Mar 2011 by fjdiewornncalwe
Simple... Your endpoint is incorrect.On your computer it works because the endpoint is local
15 Mar 2011 by Espen Harlinn
Markus is definitely on to something - that binding will not work for deployment.I'd also wrap the Grid1.ItemsSource = e.Result; in a try/catch block, like:void webclinet_GetRowsCompleted(object sender, GetRowsCompletedEventArgs e) { try { webclinet.GetRowsCompleted -=...
3 Jul 2013 by siddharth629
When ever i am generating the excel report then an authentication windows appear. and below is the message which i show in event viewer Event code: 4011Event message: An unhandled access exception has occurred.Event time: 4/07/2013 4:25:19 PMEvent time (UTC): 4/07/2013 6:25:19...
27 Jul 2012 by amineel9
hi everyone, i'm trying to retrieve my contacts , using ContentResolver.query(..)the problem is, i have like 5000 contacts, and when running, it runs out of memory, it's working fine though with something like 1000 contacts, what should i do here is the code for the cursorfinal...
6 Aug 2012 by AndroidVivek
Go to setting manage application and click on one by one application and transfer it into the card memory...Don't forget to make sd card...
7 Sep 2022 by Bruno van Dooren
Symantec can cause valid applications to crash and be gone without a trace
22 Feb 2012 by cass3000
I have the next code in my Main procedure:Public Shared Sub main(ByVal args() As String) Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Dim appdomain As AppDomain = appdomain.CurrentDomain AddHandler...
22 Feb 2012 by Sergey Alexandrovich Kryukov
You need to add one more step:using System.Windows.Forms;//...Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);When you add it somewhere in the very beginning (I usually do it in my application entry point, usually Main), it will work exactly as you...
13 Aug 2014 by Mohammed Asaad
Look the following codestatic class Program { /// /// The main entry point for the application. /// [STAThread] [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)] static...
13 Aug 2014 by Sergey Alexandrovich Kryukov
In "But it didn't catch the following exception" the "following" is not exception, period. The question makes no sense at all. Maybe you really have some exception somewhere, but your problem is not exception, but lack of understanding and the failure to present a comprehensive issue...
26 Nov 2012 by DevAffair
IDE: VS 2010OS: Windows 7IIS: 7.5Mode: Integrated..Net: 4Language: C#I have an asp.net application (not MVC) and I'm trying to catch all unhandled exceptions.I've tried with global.asax -> Application_Error, but I read that because of the integrated mode -> I can't do...
8 May 2015 by Member 11676749
Alright, I'm having hard time figuring our how I can assign default values to the elements of the list (Trees and nodes) so I don't get NullReferenceException.The basic idea of the code is:List contains from Trees, each tree contains 2 nodes, each node contains 2...
8 May 2015 by Maciej Los
I'd suggest to read this: Binary Trees and BSTs[^] and this: Implementing a Binary Tree[^]. The second article is about VB, but it might help you to understand how to achieve that.
8 May 2015 by OriginalGriff
No, you don't. The problem is that you aren't checking that each Branch actually exists: so when you get this far:List[i].Left.the Left Branch is null - so when you try to use it you get an exception. This isn't a fault: a null would be normal to indicate "end of tree".What you need to look...
2 May 2015 by Rahul83
Hi,I get an exception in Authorization module which i am handling in Application_Error handler (also i am calling Server.ClearError()) since i want to sent custom error page with some error info to user.I am surprised to see that final response sent to user have error response + response...
26 Aug 2015 by CBO1987
Hello,I am trying to publish my mvc 5 web application to a server (Arvixe Personal Class ASP). I am receiving 500 Internal Service Error after it has been published when I go to visit my page. I am not sure if this has to do with the local databases that I added in when I was creating my...
26 Aug 2015 by Afzaal Ahmad Zeeshan
Short answer: Your application does not have permission to read or access a location for the code. The program is thus inaccessible, causing this exception. This exception comes from Windows Runtime, so behind the scenes of .NET framework (which usually backs up ASP.NET) there are components of...
4 Feb 2016 by KathleenV
I found a solution in the following post on stackoverflowc# - Problems publishing a website on smarterasp.net with csc.exe file included? - Stack Overflow[^]
26 Aug 2015 by CBO1987
I am trying to login to my mvc5 web application and receiving this error. I believe that the database with the users was not attached properly when the site was published. It was attached to a database that was created on the hosting (arvixe) at first. I am wondering either how to connect a...
26 Aug 2015 by Afzaal Ahmad Zeeshan
Indeed that is the problem, the problem in real is not with your database file itself but with the connection. The SQL Server itself was not found, perhaps: 1. SQL Server version-mismatch 2. SQL Server existence3. Access permissions would be a cause to this. In my opinion, option 2...
17 Dec 2015 by Kshitij_S
Hi,I know there is a error handling middleware by default registered in the Startup.cs file. But my question is around what is the recommended approach for error handling in below two scenariosScenario 1:1. Exception occurring in the Startup file before registering the error...
22 Sep 2020 by angusmax
I have a long sequence of calculations (using variables of type "double") where some operations might result (depending on input values) in "NaN" or "Infinity".Since I don't want to add something like the following:if ((double.IsInfinity(result)) || (double.NaN(result))) {...}after...
7 Jun 2013 by Ahmed Bensaid
Hello,I think you'll need to raise the exception yourself like this :if ((double.IsInfinity(result)) || (double.NaN(result))) { throw new ArithmeticException();}
19 Dec 2011 by jmp26
Starting the (long?) migratory path from MSAccess/VBA to Net web apps, I want to learn about using MVVM with AvalonDock and WPF. Running both of the sample apps for AvalonDock 1.3 and AvalonDockMVVM ( Ashley Davis) under VS2010 with Net 4.0 result in the same error once I start manipulating the...
9 Feb 2011 by Al-Farooque Shubho
An effort to derive a basic Exception Management design guideline for N-Tier ASP.NET applications
28 Apr 2012 by ManojKumar19
Server side logging for Silverlight applications using NLog 2.0
10 Sep 2014 by Franz.net
Hello,it's been a while since i last posted a message on this site. Usually i can find what i'm looking for, but not today.What i'm trying to find is an easy way to centralize exception messages in a .Net application. So the whole exception handling is taken care of, but currently the...
10 Sep 2014 by CPallini
Possibly this Code Project article fits your needs: "Exception Handling Best Practices in .NET"[^].
20 Jun 2012 by Aero72
Dear all,I'm pretty sure I know what the problem is....could I please ask for your time and consideration as to the optimum course of actionI have an application which gets data from a USB source and stores that data in a list. For convenience during development, I made it a public...
20 Jun 2012 by Sergey Alexandrovich Kryukov
A static collection is a typical source of a "memory leak by design". In .NET, you are more or less protected from the casual memory leaks, because you don't have to clean up memory after every operation you use it; the Garbage Collector (GB) takes care about it. Despite of the common believe,...
20 Jun 2012 by DaveyM69
What sort of data are you storing in your list? I have used (in testing) extremely large lists without issue.The size of any item in .NET is limited to 2GB. The maximum value for a lists capacity is 2147483647 so theoretically you could store that many bytes in the list and be right on the...
22 Aug 2014 by abacrotto
I have a strange behaviour in the binding of some controls in my solution. The control is a TextBox control that handles numeric behaviours. I am working with a decimal textbox for instance. When I do bind the control to the Decimal property (sometimes to the .Text property too) the .NET...
3 Nov 2012 by Grant Harmer
Managing exceptions when consuming WCF services via the BizTalk ESB Toolkit
11 Sep 2012 by John Bhatt
How can I block some website permanently like (facebook.com) and more social site on my employees computers
15 Aug 2016 by David Dimalanta
I tried using this[^] tutorial from the App Guruz website to observe and point out the errors on not showing the leaderboard UI. Not only the codes but also the plugins as well. (see this link[^] below for more info) By the way, i'm using Unity, making games. After I succeeded in showing...
18 Jul 2017 by Member 13302374
Hi, I am answering this questions where there are two possible exceptions, depending on a condition. The question is: The system has generated a set of 5 employee names, but their may be bugs. Return the 4th name from the array, but be careful there is two possible problems if the array does...
18 Jul 2017 by Satya Prakash Swain
public static string PointOfFailure(string[] employeeNames) { try { return employeeNames[3]; } catch (System.IndexOutOfRangeException e) { return "Array not valid length";...
15 Jun 2013 by sizusuzu
I am working on Emgu cv as a console application and I was trying to load an jpeg format image file from computer disk.I have tried the following ways but nothing is working?Image input = Image.FromFile("C://Users//...//Image.jpg");Bitmap master = (Bitmap)input;Image...
15 Jul 2022 by Mark Pelf
We explain how to debug and get more information on the generic Exception “Failed to enable constraints.”
4 Nov 2010 by Jeff Patterson
I am wondering if there is a more eloquent way to express the code below? I can't seem to get the IsNullOrEmpty method to work with data inside of a DataGridView so whenever a cell is null an exception is thrown.This works, but it seems to be a bit of a work around (maybe not) and I have the...
4 Nov 2010 by Henry Minute
I don't know of a more elegant way, although somebody probably will.The only thing I would say is that it could be very slightly shorter if ( ( !string.IsNullOrEmpty( row.Cells[ "Quantity"].Value.ToString() )) && ( !string.IsNullOrEmpty( row.Cells[ "Unit"].Value.ToString() ))...
4 Nov 2010 by Nish Nishant
The problem in that code is that row.Cells[ "Quantity" ].Value can be null, but you call ToString on that without checking for that.Change:string.IsNullOrEmpty( row.Cells[ "Quantity" ].Value.ToString() )tostring.IsNullOrEmpty( row.Cells[ "Quantity" ].Value as String)Btw...
14 May 2013 by Zain ul abdeen
CodeSqlConnection con = new SqlConnection(@"server=ZAIN\SQLEXPRESS;database=Project;user id=sa;pwd=abdeen"); SqlDataAdapter com = new SqlDataAdapter("execute UpdateShopDetails '" + txtName.Text + "','" + txtAddress.Text + "','" + txtPhoneNo.Text + "'", con); ...
14 May 2013 by Mahesh Bailwal
Your getting this error because your subquery is returning more than one value and you are using “=” operator which is anticipating single value. One to way solve the problem is to use “TOP 1” in your subquery.For Exampleset Sid=(select Top 1 Sid from Shops Where Name= @Name)
14 May 2013 by OriginalGriff
First off, can I suggest that you only read the Sid and ContactId once per execution, and store them in a variable? Then ensure it returns only a single value:DECLARE @SID INTSet @SID = (SELECT TOP 1 Sid FROM MyTable WHERE Name=@Name)Then use the variable in each of your updates.
9 Feb 2011 by antti.arrak
My console program loads a dll to different appdomain.That dll communicates with webservice but it gives a exception :On GetWebRequest()"exePath must be specified when not running inside stand alone exe.at System.ConfigurationManager.OpenExeConfigurationInternal(.....)".As far as I...
8 Feb 2011 by #realJSOP
Does your DLL call ConfigurationManager.OpenEXEConfiguration()? If so, try putting a try/catch block around it and just eat the exception.
9 Feb 2011 by #realJSOP
Try removing the web service reference from your app, and then re-adding it.
24 Nov 2023 by PinkGoat_
So I have a button made from my xaml file (view), called Export. When the user clicks on it, the logs created during the run of the app get exported to Logs.txt. If there are Warnings, Errors or Exceptions, those will instead be created in...
24 Nov 2023 by Graeme_Grant
The best solution, IMHO, would be to create a custom log provider. You can then handle the logging as the log entries are added. I wrote an article for a custom Log Viewer control that has a custom Log Provider, one for each of the 4 common...
9 Jul 2014 by memd24
Hi, I am trying to upload files from one server to anotherEverything works fine with small files(
10 Jul 2014 by Jeffrey Bruskin
Since its a large file the OS will send it in chunks. Probably there is still some bytes in the buffer when you go to close it. Try uploadStream.Flush() before closing the stream to write the last of the bytes to the stream first.
29 Aug 2016 by Sergey Kizyan
My lecture #8 about exceptions handling and organization of error handling in the project
28 Oct 2015 by Rencyrence
I have problem with connection String, Error (Object reference not set an instance of an object) how to debug this pleaseMy app.config ...
28 Oct 2015 by phil.o
The problem is not the connection string.A NullReferenceException is throw when you try to access an instance member of a given variable while this variable has not been initialized, or been disposed.Somewhere in your code file, there is a line where you are using a variable of which you...
28 Oct 2015 by Garth J Lancaster
I dont know if its just the way you've posted that info in your question, but, it appears as though your connectionStrings is part of/'under' startup - I dont think it should be - try moving it 'up' a level' or at least change this
16 Dec 2010 by Jibrohni
Ok, so I'm using some code that adjusts an images contrast:public static Bitmap AdjustContrast(Bitmap Image, float Value) { Value = (100.0f + Value) / 100.0f; Value *= Value; Bitmap NewBitmap = (Bitmap)Image.Clone(); BitmapData...
16 Dec 2010 by E.F. Nijboer
Are you sure the image is 32 bit per pixel and not 24 bit per pixel? Check out the PixelFormat and use the size of that.columnOffset += Image.GetPixelFormatSize(NewBitmap.PixelFormat);http://msdn.microsoft.com/en-us/library/system.drawing.image.getpixelformatsize.aspx[^]As side...
16 Dec 2010 by Jibrohni
public static Bitmap AdjustContrast(Bitmap Image, float Value) { Value = (100.0f + Value) / 100.0f; Value *= Value; Bitmap NewBitmap = (Bitmap)Image.Clone(); BitmapData data = NewBitmap.LockBits(new Rectangle(0, 0,...
14 Jul 2020 by Rencyrence
Hello, here's the scenario:Im using datagridview to export data to Excel, after many times of exporting, i have noticed that my computer become slow, and check the Processes and i saw that there's too many Excel.exe running. What i did is I closed the Application and it removes on the...
5 Jan 2016 by Abhinav S
Try How to properly release Excel COM objects: C# code examples[^].
5 Jan 2016 by Mathi Mani
Since you have used Excel.Visible = true, excel will be visible to the user on screen. So what to do with the excel on screen is up to the user. User can either save it and close it or just discard it without saving. And when the user closes the excel the program, the process also should be...
5 Jan 2016 by koolprasad2003
EXCEL and WORD are very and unmanaged objects, so GC is unable to collect them In EXCEL case first we need to we need to use 'Marshal.ReleaseComObject' method to release COM object or each sheet and then we need to dispose EXCEL Workbook first and then quit to EXCEL application object see...
14 Jul 2020 by Member 10187249
Above all solution are correct only one thing missing, still in the background task excel empty object still run for remove that you can put below code at last: Process[] excelProcesses = Process.GetProcessesByName("excel"); foreach...
1 Dec 2018 by TheBigBearNow
Hello all, I have a C# WPF application that I log into and I pass the user to the next screen. Then I click to go to a profile screen and if the user already has profile data I autopopulate all the fields. In my profile screen I have it so when you set the combobox to ‘Yes’ it creates the...
1 Dec 2018 by #realJSOP
I know - it's unfortunate that you have to actually write some code, but that's how it goes. Put a try/catch block around the code that's attempting to insert the new user, and in the catch part, show a message box that shows "User name already exists.", and let that be that. At the same time.
9 Nov 2018 by TheBigBearNow
current error: Object reference not set to an instance of an object I was getting invalid cast exception error but i changed (int) to Convert.toInt32 and that went away. I go to debug it and the on my button click and the code runs all the way through not stopping at any of my breakpoints. The...
9 Nov 2018 by OriginalGriff
The debugger is pretty much the only way you will find this: if you aren't hitting the breakpoints, then either they aren't in the right place, or you are not debugging the code you are executing. So: try it again. Go to the "Debug" menu and select the "Exceptions..." menu item. In the...
30 Nov 2018 by TheBigBearNow
Hello all, I have a question with C# WPF I have a window that passes a User object into the next window and in the constructor I am setting a default combobox value to what the users property is. In the combobox_Selection() I have it so when this specific property is selected a...