Click here to Skip to main content
15,891,657 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 Updated

Exceptions 

27 Nov 2023 by Mircea Neacsu
You might try to use my error code objects. They are a cross between exceptions and error codes. See C++ Error Handling with Error Code Objects[^]. Latest version of code can be downloaded from GitHub - neacsum/mlib: Multi-Purpose Library[^]
25 Nov 2023 by Code_bro
Hi, i like to make my class working with exceptions or if needed not working with exception. I like to make them switchable. I made a serial port class and it throws me exceptions as i need. But when i choose to not use them how can i get this...
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...
10 Feb 2023 by FosanzDev
I was defining a new type of Exception to 'replace' IndexOutOfBounds exception. In first instance I defined a new Class: public class NoNextItemException extends Exception { public NoNextItemException(String message) { ...
10 Feb 2023 by Richard MacCutchan
public double peek() throws NoNextItemException { That statement tells Java that the peek method may throw the NoNextItemException. But since this is a Throwable exception, it must be caught in any methods that include a call to peek. When you...
27 Jan 2023 by Arnaav PL
Design a class ReserveTicket with an instance variable seatsavailable, and a method void reserve ( int numberofseats). If `numberofseats' is greater than `seatsavailable' then throw a user defined exception SeatFullException otherwise throw a...
27 Jan 2023 by Richard MacCutchan
Quote: i am new to java and idk how to do this Then the first thing you need to do is to go and learn it from the ground up: Java Tutorials Learning Paths[^]
27 Jan 2023 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
8 Jan 2023 by reverser69
hi all i have a target app written in Java. i want to call one of its functions. im using Intellij Idea. i imported its dependencies. wrote a few lines of code and till now, i have two problems. 1. i get: Exception in thread "main"...
8 Jan 2023 by Richard MacCutchan
1. See the discussion at https://stackoverflow.com/questions/34855649/invalid-signature-file-digest-for-manifest-main-attributes-exception-while-tryin[^]. 2. The log4j library is not part of a the standard Java libraries, so you need to include...
7 Sep 2022 by Bruno van Dooren
Symantec can cause valid applications to crash and be gone without a trace
15 Jul 2022 by Mark Pelf
We explain how to debug and get more information on the generic Exception “Failed to enable constraints.”
27 Jun 2022 by Greg Utas
Keeping a program running when it would otherwise abort
17 Jun 2022 by Mircea Neacsu
C++ thread objects and their use
25 May 2022 by Ravi-from-India
Hello, I have an API in which I have implemented custom exception filter. so, basically I don't have try/catch block in my controller. Just customErrrorAtrribute is there in my controller. Normally, I write code for my database connectivity...
25 May 2022 by Richard Deeming
Always wrap disposable objects such as SqlConnection / SqlCommand in using blocks. That way, they will always be disposed of properly. Eg: using (SqlConnection con = new SqlConnection("connection string")) using (SqlCommand cmd = new...
25 May 2022 by lmoelleb
You have moved the small peace of code reporting any exception as an API Json object (or whatever you use) - anything else related to try/catch/finally blocks should still remaining where it is. So you still need try/finally blocks to ensure...
21 May 2022 by Temba Lumbuka Mwamba
I keep receiving Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4 at covid19.Covid19.main(Covid19.java:70) but the array I used is null so it shouldn't have a specified length What I have...
21 May 2022 by OriginalGriff
We have no idea which lin e is line 70 - from the error message: Index 4 out of bounds for length 4 at covid19.Covid19.main(Covid19.java:70) So the first thing you need to do is work out which line it is. Most editors support CTRL+G to go...
12 May 2022 by Tyrunt.new("Rix")
Oh, I just needed to add `end` in the `stick(place)` function!
12 May 2022 by Tyrunt.new("Rix")
Hello, coding guys, As you saw in the title, Ruby is throwing me: main.rb:59: syntax error, unexpected end-of-input, expecting `end' and, this is my code: # Logging puts "Hello, world!\n" # Input getting & variables puts "What is your name?"...
17 Mar 2022 by Cameron Grant 2021
I've found that if I use the try with resources feature java provides which will automatically close of resources, I then can't use a boolean flag (or recursion) to resolve an InputMismatchException within a try catch as the catch block seems to...
17 Mar 2022 by Richard MacCutchan
The Scanner object only exists within the try block, so you cannot refer to it in the catch. And you specifically should not be doing so. You should rework the code so that the Scanner is instantiated before the try, and is not referred to in the...
13 Mar 2022 by Cameron Grant 2021
I am trying to work out how to implement text to speech with java 11 and have written some classes in order to read a text ("Dracula") and then and option to speak the text. Classes: package draculatext; import java.io.BufferedReader; import...
13 Mar 2022 by Richard MacCutchan
The error message is telling you that the system cannot find the VoiceManager, which suggests that it is not aware of the location of the jar file(s). Make sure that the file's location is passed to the virtual machine by adding it as follows: ...
17 Feb 2022 by Roger Burke
Hi got a project that used LinqToSQL for database access and is now being converted to Entity Framework Core. Most conversions are ok but have come across this one that I am having trouble with...what happens if you have a db conflict on save....
17 Feb 2022 by Richard Deeming
Handling Concurrency Conflicts - EF Core | Microsoft Docs[^] Tutorial: Handle concurrency - ASP.NET MVC with EF Core | Microsoft Docs[^]
11 Jan 2022 by Member 15127345
I'd like to iterate through the tuple in a for loop, like this: for i in 0...4{ if let value = element.list_of_keywords?.i, value == keyword { if let value = element.name{ returnListOfCities(name: value) ...
2 Jan 2022 by Member 15127345
The issue was in the second constructor. I had to change one line of code. constructor(resourceId: Int): this(resourceId, false) Reason why I had to do this: I was calling another constructor, but I wasn't saving values back to the Stage class...
2 Jan 2022 by Member 15127345
I'm writing an app in Kotlin, which displays 2D object on user's phone. When I execute my code, I get Java.lang.nullpointerexceptionRun. Sadly, I don't know how to fix this issue. Run output: E/com.a3dmodelap: Invalid ID 0x00000000....
2 Jan 2022 by 0x01AA
How is about to check wheter val bmp = BitmapFactory.decodeResource(context.getResources(), resourceId, opts) returns a 'not null' value? And in case it returns null you need to investigate why...
2 Jan 2022 by Luc Pattyn
it looks like bmp is null due to resourceId being zero. And you did not show any code that sets resourceId...
29 Nov 2021 by Member 15435322
This is my method, which I am using Optional to avoid NullPointerException, but I want to do that using without if else statement to avoid nullpointer exception. is it possible or is there any way, that I say using without if else statement...
29 Nov 2021 by OriginalGriff
The null checks are there for a reason - to make sure that there is a User, that the user has an Address, and the address includes a State - without these, there is no information to process - and the null return is the way the method tells you...
19 Nov 2021 by jgauffin
codeRR is an open source error handling service. It includes the context information that you forgot to include when you logged/reported the exception.
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 Oct 2021 by Dave Kreskowiak
Look at what you appear to be doing: String phoneNumber = ""; String textMessage = ""; FileInputStream excelFile = new FileInputStream(file); Path sourcePath = Paths.get(String.valueOf(file)); Path targetPath =...
14 Oct 2021 by User 15041314
This is my code, which accept generally .xlsx format file and insert to database and also move accept file to my specified folder. When I trying to move it, I have getting this error: Normally, it successfully writes the received excel file to...
13 Sep 2021 by wa.war
I understand that the API could be returning status codes like this:200 - OK400 - Bad Request500 - Internal Server ErrorHere is my code, how to handle the error from API in my controller?public ActionResult Get() { string token_access =...
13 Sep 2021 by Oscar Valdez
IRestResponse response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { } else if (response.StatusCode ==...
19 May 2021 by dj4400
Hi, I have a native c++ app. that uses a clr/cli wrapper to call a c# dll function. The solution is built in VS.2017, using the platform toolset of vs2010(v100) and includes the native c++ project, the clr/cli wrapper project and the c# dll...
19 May 2021 by Dave Kreskowiak
That's not an exception. It's just a debugger message that says it cannot load the symbols from the PDB file for the wkernelbase assembly. There's nothing to worry about there. If you want to get rid of it, you can enable automatically...
16 Apr 2021 by GlennAshan
I'm getting this following exception to my log file when I try to run the windows service, Exception: The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects. What should I modify to avoid this exception?...
16 Apr 2021 by Richard Deeming
Try replacing: cmd.Parameters.Add($"@p{i}") with: Dim p As SqlParameter = cmd.CreateParameter() p.ParameterName = $"@p{i}" cmd.Parameters.Add(p)
12 Apr 2021 by Patrice T
Quote: The instructions for this assignment are unclear and was not given example code Since the job of programming is about creating algorithms/programs, your sentence is weird. It is like saying that you are a cook dying from starvation...
12 Apr 2021 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
1 Mar 2021 by MehranSarrafi
Hi In the C# program, I want to call a function to screen capture and save it to the database, when an exception occurs and the program is in a stopped mode. What I have tried: Hi In the C# program, I want to call a function to screen capture...
1 Mar 2021 by MehranSarrafi
Thanks, I found out my solution and I write down here; and I hope it will be useful for others. I catch the exception with try catch block and call my function to do what I need in a new thread; and then throw the exception again with the main...
23 Feb 2021 by OriginalGriff
If your app has stopped, you can't do anything: you need your code running in order to do anything. So by that time, it;'s too late - the idea is to spot problems before they become fatal, and do something useful then; then continue or fail the...
13 Jan 2021 by lil_mint
This is for my project. My problem is I don't know how to display an error message inside my class function code. Error message must display if the user entered a non-parenthesis character. What I have tried: open_list=['(','[','{']...
11 Jan 2021 by Sandeep Mewara
Would suggest you to use User-Defined Exception in Python using try-except Refer: How to Define Custom Exceptions in Python? (With Examples)[^] Example from there: # define Python user-defined exceptions class Error(Exception): """Base...
16 Dec 2020 by Dev Parzival
bool insertIntoTable(string database,string table, string query){ cout
16 Dec 2020 by OriginalGriff
executeQuery returns a result set, which you are not handling - so when you try to delete everything else, it finds an open result set on the connection and fails. You use executeQuery when you want to fetch data from the DB, not add it: use...
7 Nov 2020 by Lucas Dana
Good morning, I would like to know how I can check if a stack is empty and in that case throw an exception. The idea is to have a main class, and other classes that do the tests. Thank you, Luke What I have tried: Class Stack public...
15 Oct 2020 by ZhaoChaoHui
There are some bugs I can't solved in My WinForm Application. My WinForm Application process exit suddenly in abnormal with low probability, and it can't catch any exception before exit. The code of WinForm Application contain this: ...
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...
16 Jul 2020 by User 14853400
why unchecked exception can be undeclared in java ? But for checked exceptions you have to declare the type. i know unchecked exception happen at runtime but how that let's you to have a choice to declare or undeclared the class type What I have...
16 Jul 2020 by Richard MacCutchan
You cannot normally recover from Unchecked Exceptions so it is difficult for the programmer to anticipate them at code creation time. See Unchecked Exceptions — The Controversy (The Java™ Tutorials > Essential Classes >...
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...
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...
9 Jul 2020 by saransaki08
Hi guys, When I receive data sent from one application to another application I get an error. One application acts as the server and sends data to the client that connected to the server on a particular port.I sent some information via clientsocket and at that time I got this...
9 Jul 2020 by Member 14885591
mesmo colocando 1024 nao funcionou
2 Apr 2020 by Richard Deeming
I suspect the problem is that you are storing your OleDbCommand object in a class-level field, and reusing it across methods. Change your code to create the command instance when you need it, and wrap it in a Using block, and your error will...
2 Apr 2020 by lelouch_vi 2
Hello, I'm having a hard time solving this one I'm working with vs2017 and access as my database. I don't really know what happened here. I have a COMBOBOX that displays the name of all category name field from my database and from there I can...
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...
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. ...
22 Jan 2020 by phil.o
Trying to write anything at the root of a drive will be problematic on any recent Windows version; better create a directory on the D: drive and write your files in it instead.
22 Jan 2020 by Oleg Pruh
Hi, I'm Oleg. Today I want to build a progect in Unity 2017.4.36f1 (64-bit) and then me in the Colsole appeared Error about UnauthorizedAccessException: Access to the path "D:\" is denied. Please HELP me with that problem. More information you can see here. UnauthorizedAccessException: Access...
22 Jan 2020 by OriginalGriff
We can't help you. We don't have access to your code, or your data, or your system: so we have no idea what kind of access you are trying to get to the root of drive D:, or even that D: exists on your computer. Probably it does exist: the error message is telling you that your application (or...
22 Jan 2020 by F-ES Sitecore
Ensure your account has access to the D;\ drive. If you are creating a project directly in the root of the D drive, or have anything that creates files in the root of the D drive then make sure it doesn't, always work in sub-folders and sometimes access to the root can be blocked. If you don't...
20 Jan 2020 by Paramu1973
Hi, I have a small project in VS2015, Windows Forms Applications accessing via shared folder using UNC paths for 4-systems. Windows Forms have OpenFileDialog() control. Actually it's working good in 3 systems. But 1 of the remaining user system showing exception 0x732E1175 (uxtheme.dll), at the...
17 Jan 2020 by Member 14719581
Hello guys! whats up? I'm trying couple of hours to solve an annoying mistake and get the expected result but every try i do fails. Could you help me please? This is my source code: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include ...
17 Jan 2020 by Patrice T
Quote: I cant figure out my mistaked in C code You forgot to tell what is supposed to do your code ! We can't guess ! You forgot to tell us how the code go wrong (how you know it is wrong). The only sensible advice is to learn how to use the debugger. ----- Your code do not behave the way you...
17 Jan 2020 by OriginalGriff
We have no idea what you expect that to do: even with the data, reporting it as "it don't work" doesn't help anybody - we can't see your screen, can't access your HDD, or read your mind. And we don't know what your tutor asked you to do! So, it's going to be up to you. Fortunately, you have a...
28 Dec 2019 by Jassim Rahma
Hi, I am getting General Error but can't find the reason. The error I am getting is: PDOException: SQLSTATE[HY000]: General error in /home/domain.com/api/signin.php:40 Stack trace: #0 /home/domain.com/api/signin.php(40): PDOStatement->fetch() #1 {main}Connection failed: SQLSTATE[HY000]:...
15 Oct 2019 by dashingly
I am getting "HRESULT: 0x800A03EC" error when running Excel add-in with following code: Excel.Range rng = ActiveSheet.Cells[x, y] as Excel.Range; string before = rng.Value2; string cleanV = System.Text.RegularExpressions.Regex.Replace(before, @"\s+", ""); ...
16 Sep 2019 by Member 14557501
Okay... Once I walked away from the problem for a couple of days, and gave OriginalGriff's answer time to percolate in my subconscious, I found a solution. Looking at the code in my problem update, there is only one statement that opens a file, the "OpenFileDialog1.OpenFile()". I commented...
16 Sep 2019 by Member 14557501
I am testing a new Visual Basic 2017 app which will let users select a file from a directory for processing. After processing the app is intended to move the file to a backup directory. This works for the first file just fine, but on the second file I get: System.IO.IOException: 'The process...
13 Sep 2019 by OriginalGriff
Since your app is processing a file, it;'s highly likely that your app still has it open, and thus it's in use when the CopyFile call is made. Since it's opened for writing by something, it can't be opened for reading - the "open for write" operation establishes an exclusive lock on the file to...
24 Apr 2019 by Member 14328281
solamente evita usar nombres tan largos y cambia la direccion del proyecto a una ruta mas corta un ejemplo pasala al C y si tu proyecto se llama parangaricutirimicuariquense_mi_proyecto cambiale el nombre a ese proyecto a uno mas cortito y vuala
21 Apr 2019 by Happy_Accidents
I have no errors in my code, at least from what I can see on the error list. but every time I run my code it comes up with a system.formatexception. am new to coding and VB.NET so any advise on what I can do to solve this problem would help. What I have tried: Private Sub...
21 Apr 2019 by Gerry Schmitz
You wrote a method to format Currency; do the same for doubles. You can do the Double.TryParse in the routine and any default / error handling; returning a valid number. That way you limit the amount of code you need to write.
6 Mar 2019 by cass3000
I have a problem with the serial port:My code:Dim readData() As ByteDim port As New SerialPort("COM1", 38400, Parity.None, 8)port.StopBits = StopBits.Oneport.Handshake = Handshake.Noneport.ReadTimeout = 1000port.Open()port.Read(readData, 0, 8)If readData.Length > 0...
10 Feb 2019 by Esraa Saady
i want to call function in matlab from c# inside for loop using com componentwhen i tried it i had this exceptionInvalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))this is the codefor (int j = 1; j
10 Feb 2019 by Member 14145676
Hi, I'm sad to see all the unhelpful comments above when it is really Mathwork's poor implementation leading to this error. The solution is to simply include result = null in your for loop: for (int j = 1; j
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.
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...
30 Nov 2018 by Graeme_Grant
The code is doing exactly what you have asked it to do. When the selection changes, default is no selection, the SelectionChanged is fired from the ctor method. IF you set a breakpoint on the line CboCustomer.SelectedIndex = 2; then step through the execution line by line, you will see this...
28 Nov 2018 by Shai Cohen
By utilizing some fairly mundane features of .NET, we can log errors at the point where the exception occurred; preserving vital debug information while avoiding repetitive error logging.
21 Nov 2018 by Member 14051204
I am in a university project group of six people, and we are using C# (with Microsoft Visual Studio 2017 as IDE) to make a program, that can manage a beer production system. I have a weird problem that i have no idea how to fix. Whenever I through Visual Studio, try to connect to a database or a...
13 Nov 2018 by Aydin Homay
Hi, The information that you provided is not enough and to complicated. You are referring to several problems. Let`s make progress step-by-step. Follow my solution and leave comments I will read and change/improve the solution according to your progress until we get it solve. Ok? So first,...
11 Nov 2018 by Aydin Homay
Hi I am more suspicious to the below line: ComboboxState.SelectedValue.ToString() Could you please do a favor and re-write your code in this way: var userId = currentUser.UserID; var firstName = TextboxFirstName.Text; var lastName = TextboxLastName.Text; var address = TextboxAddress.Text;...
11 Nov 2018 by TheBigBearNow
Hello, I am getting the error object reference is not set to a instance I am creating a new customer in the combobox select method but in the button click I go to update the customer but I get an error where I am updating the customer object. The error is here in this btn click: this exact...
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...
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...
20 Sep 2018 by OriginalGriff
You get an "Access violation" error when the process trying to open a file does not have sufficient permissions for it. So start by looking at the file you are opening, the folder that contains it, and see exactly where it is, and what users have access rights. It's possible that Access 2016...
20 Sep 2018 by yash1507
Hi, Earlier ms access 2013 version was installed on machine. Now, ms access 2016 version has been installed. I didn't make any changes in code, but i am getting "a first chance exception of type 'system.accessviolationexception' occurred" error. I am using Microsoft Visual Studio...