tagged [exception]

How to handle exceptions in Parallel.ForEach?

How to handle exceptions in Parallel.ForEach? I have a `Parallel.ForEach` loop in my code and I am wondering how to handle exceptions. Should I catch and handle(e.g write to log) exceptions inside the...

What is the best way to communicate that your constructor has failed in C#?

What is the best way to communicate that your constructor has failed in C#? In C# I want to communicate to the calling method that the parameters passed to an object have caused its instantiation to f...

23 Jan at 01:39

Stack smashing detected

Stack smashing detected I am executing my a.out file. After execution the program runs for some time then exits with the message: What could be the possible reasons for this and how do I rectify it?

18 Sep at 03:0

finally doesn't seem to execute in C# console application while using F5

finally doesn't seem to execute in C# console application while using F5 The finally block does not seem to execute when pressing F5 in VS2008. I am using this code in Console Application.

How to print an exception in Python 3?

How to print an exception in Python 3? Right now, I catch the exception in the `except Exception:` clause, and do `print(exception)`. The result provides no information since it always prints ``. I kn...

C# equivalent to VB.NET's Catch...When

C# equivalent to VB.NET's Catch...When In VB.NET I often `Catch…When`: Is there a C# equivalent to `Catch…When`? I don't want to resort to using an `if` statement inside a `catch` if possible.

16 Aug at 11:7

What exception type should be thrown when trying to add duplicate items to a collection?

What exception type should be thrown when trying to add duplicate items to a collection? Following code should throw exception to prevent adding duplicate collection item. What standard exception type...

23 Jan at 15:15

Ignore Exception in C#

Ignore Exception in C# Is there a better way to ignore an exception in C# than putting it up in a try catch block and doing nothing in catch? I find this syntax to be cumbersome. For a codeblock, can'...

6 Feb at 12:6

Java RuntimeException equivalent in C#?

Java RuntimeException equivalent in C#? Does C# have the equivalent of Java's [java.lang.RuntimeException](http://download.oracle.com/javase/1.5.0/docs/api/java/lang/RuntimeException.html)? (I.E. an ...

Use NUnit Assert.Throws method or ExpectedException attribute?

Use NUnit Assert.Throws method or ExpectedException attribute? I have discovered that these seem to be the two main ways of testing for exceptions: Which of these would be best? Does one offer advanta...

catch exception that is thrown in different thread

catch exception that is thrown in different thread One of my method (`Method1`) spawns a new thread. That thread execute a method (`Method2`) and during exectution an exception is thrown. I need to ge...

12 May at 20:27

How to use ELMAH to manually log errors

How to use ELMAH to manually log errors Is it possible to do the following using ELMAH? I'm doing something like this: This exception will not be automatically logged by ELMAH, because it was handled.

17 Oct at 07:55

Correct Usage of ArgumentException?

Correct Usage of ArgumentException? From what I've seen, `ArgumentExceptions` are usually used like such: but what if I have something like this: ``` public void UpdateUser(int idOfUser) { var user ...

22 Jun at 13:16

Exception messages in English?

Exception messages in English? We are logging any exceptions that happen in our system by writing the Exception.Message to a file. However, they are written in the culture of the client. And Turkish e...

14 Jan at 16:34

Performance Cost Of 'try' in C#

Performance Cost Of 'try' in C# I know that exceptions have a performance penalty, and that it's generally more efficient to try and avoid exceptions than to drop a big try/catch around everything -- ...

26 Oct at 17:15

C# Best way to ignore exception

C# Best way to ignore exception > [Ignore Exception in C#](https://stackoverflow.com/questions/4913159/ignore-exception-in-c-sharp) Sometimes in rare circumstances you really want to just ignore exc...

23 May at 12:32

How to test that no exception is thrown?

How to test that no exception is thrown? I know that one way to do it would be: Is there any cleaner way of doing this? (Probably using Junit's `@Rule`?)

When to throw an exception?

When to throw an exception? I have exceptions created for every condition that my application does not expect. `UserNameNotValidException`, `PasswordNotCorrectException` etc. However I was told I shou...

28 Nov at 12:47

Is there a throws keyword in C# like in Java?

Is there a throws keyword in C# like in Java? > [how to use Java-style throws keyword in C#?](https://stackoverflow.com/questions/3465465/how-to-use-java-style-throws-keyword-in-c) i have a function...

23 May at 12:32

Is it possible in Java to catch two exceptions in the same catch block?

Is it possible in Java to catch two exceptions in the same catch block? I need to catch two exceptions because they require the same handling logic. I would like to do something like: Is it possible t...

26 Jun at 16:7

C++ catching all exceptions

C++ catching all exceptions Is there a c++ equivalent of Java's I am trying to debug Java/jni code that calls native windows functions and the virtual machine keeps crashing. The native code appears f...

14 Jan at 15:4

Show line number in exception handling

Show line number in exception handling How would one display what line number caused the error and is this even possible with the way that .NET compiles its .exes? If not is there an automated way for...

25 Oct at 12:8

More Elegant Exception Handling Than Multiple Catch Blocks?

More Elegant Exception Handling Than Multiple Catch Blocks? Using C#, is there a better way to handle multiple types of exceptions rather than a bunch of ugly catch blocks? What is considered best pra...

26 Apr at 19:0

Exception for missing data

Exception for missing data I was wondering what kind of exception should one throw for missing data. For example if an xml node doesn't contain data. It would be easy to "" but this is not recommended...

21 Sep at 07:15

Throw an exception in try catch block

Throw an exception in try catch block My question is would the `catch` catches the `ApplicationException` thrown in the try block? is it in poor coding style? Should it be written in another wa

1 May at 05:0