tagged [exception]
What's the use of a finally block preceded by a catch-all catch block, in C#?
What's the use of a finally block preceded by a catch-all catch block, in C#? Consider the following C# code structure (S0-S3 are placeholders for arbitrary code blocks): In the case that S1 throws an...
Exception handling loop puzzle
Exception handling loop puzzle I recently encountered a behavior that I've never seen before. I cannot quite understand what's going on most likely due to lack of fundamental knowledge with regards to...
Can an event listener be limited to only having one subscriber?
Can an event listener be limited to only having one subscriber? Is it possible to stop multiple subscribers from subscribing to an event? I have created a quick example snippet to give my question som...
C# Is there an Exception overview?
C# Is there an Exception overview? I was wondering if there's a list with all Exception types. I know a few Exceptions, but I don't know them all. Sometimes I throw an Exception and then I think, mayb...
What Exception Type to throw for strings
What Exception Type to throw for strings If I've got the following, really for any string where you check IsNullOrEmpty and it turns up empty, what kind of exception type should one throw, and ? I alw...
- Modified
- 19 Jan at 22:59
How to get a value through a out/ref parameter from a method which throws an exception?
How to get a value through a out/ref parameter from a method which throws an exception? this code outputs "out value". bu
- Modified
- 20 Jan at 11:31
Is it abusive to use IDisposable and "using" as a means for getting "scoped behavior" for exception safety?
Is it abusive to use IDisposable and "using" as a means for getting "scoped behavior" for exception safety? Something I often used back in C++ was letting a class `A` handle a state entry and exit con...
C# equivalent to Java's Exception.printStackTrace()?
C# equivalent to Java's Exception.printStackTrace()? Is there a C# equivalent method to Java's `Exception.printStackTrace()` or do I have to write something myself, working my way through the InnerExc...
- Modified
- 21 Jan at 00:52
C#: An item with the same key has already been added, when compiling expression
C#: An item with the same key has already been added, when compiling expression Ok, here's a tricky one. Hopefully there is an expression guru here who can spot what I am doing wrong here, cause I am ...
- Modified
- 21 Jan at 10:16
Response.Redirect results in "Object moved to here"
Response.Redirect results in "Object moved to here" I'm working on a C# ASP.NET page that normally ends up redirecting to a "file:" URL. This seems to work fine the majority of the time, in the majori...
Why does C# allow you to 'throw null'?
Why does C# allow you to 'throw null'? While writing some particularly complex exception handling code, someone asked, don't you need to make sure that your exception object isn't null? And I said, of...
In C# how do I define my own Exceptions?
In C# how do I define my own Exceptions? In C# how do I define my own Exceptions?
What is the right way to pass on an exception? (C#)
What is the right way to pass on an exception? (C#) I'm wondering what the correct way is to pass on an exception from one method to another. I'm working on a project that is divided into Presentation...
C#: Does Visual Studio 2008 have a tool to show which Exceptions could be raised by a piece of code?
C#: Does Visual Studio 2008 have a tool to show which Exceptions could be raised by a piece of code? For example, if I'm opening a file, I know a FileNotFoundException might happen, or if I'm converti...
- Modified
- 10 Feb at 23:17
Get a Try statement to loop around until correct value obtained
Get a Try statement to loop around until correct value obtained I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop a...
How can I improve this exception retry scenario?
How can I improve this exception retry scenario? I have a web service method I am calling which is 3rd party and outside of my domain. For some reason every now and again the web service fails with a ...
Try/catch blocks inside constructors
Try/catch blocks inside constructors Is it a bad programming practice to have try/catch blocks inside constructors? Or does it make no difference as long as our programs handle typeinitializer excepti...
- Modified
- 18 Feb at 03:30
What does the error "the exec task needs a command to execute" mean?
What does the error "the exec task needs a command to execute" mean? When compiling a project in Visual Studio, the error message "the exec task needs a command to execute" appears, with no line numbe...
- Modified
- 19 Feb at 12:59
Is it ok to catch all exception types if you rethrow them wrapped another exception?
Is it ok to catch all exception types if you rethrow them wrapped another exception? I know you're not suppose to write code that caches all exception types like this. Instead you're suppose to do som...
C# try-catch-else
C# try-catch-else One thing that has bugged me with exception handling coming from Python to C# is that in C# there doesn't appear to be any way of specifying an else clause. For example, in Python I ...
Exception calling when TimeZoneInfo.ConvertTimeToUtc for certain DateTime values
Exception calling when TimeZoneInfo.ConvertTimeToUtc for certain DateTime values When I run the code for this specific value of dt, an exception is thrown when I call the ConvertTimeToUtc Method. My l...
What is the difference between an error and an exception in .NET?
What is the difference between an error and an exception in .NET? Could you please explain to me what the difference is between an error and an exception?
what happens when two exceptions occur?
what happens when two exceptions occur? what will the program behave when they have two exceptions. And none of them have been caught yet. what type of handler will be called . lets say both the excep...
- Modified
- 13 Mar at 20:36
C#: When should I use TryParse?
C#: When should I use TryParse? I understand it doesn't throw an Exception and because of that it might be sightly faster, but also, you're most likely using it to convert input to data you can use, s...