Linked Questions
36 questions linked to/from How using try catch for exception handling is best practice
8 votes
1 answer
9k views
Re-throw an exception in @Around Aspect [duplicate]
Is it normal to re-throw, after some action, an exception from around aspect to ExceptionHandler in rest controller, like this: @Around("execution(* *(..)) && @annotation(someAnnotation)") ...
0 votes
2 answers
807 views
c# return that also returns the calling function - similar to PHP's die() early out [duplicate]
Note: This is a question from the PHP perspective for C#. Maybe it isn't the right way to do it, but here is what I'm trying to do. Suppose you have defined: void Die(string error){ print(error); ...
-4 votes
1 answer
220 views
Why using try/catch if I can simply fix the error? [duplicate]
I don't understand the sense of error handling with try and catch. (C#) In my online course the following example was used: class Program { static void Main(string[] args) { try ...
312 votes
11 answers
197k views
Best practices for catching and re-throwing .NET exceptions
What are the best practices to consider when catching exceptions and re-throwing them? I want to make sure that the Exception object's InnerException and stack trace are preserved. Is there a ...
211 votes
6 answers
27k views
When is "Try" supposed to be used in C# method names?
We were discussing with our coworkers on what it means if the method name starts with "Try". There were the following opinions: Use "Try" when the method can return a null value. Use "Try" when the ...
116 votes
4 answers
32k views
What's the difference between Application.ThreadException and AppDomain.CurrentDomain.UnhandledException?
Alright, this is an easy one: What's the difference between Application.ThreadException and AppDomain.CurrentDomain.UnhandledException? Do I need to handle both? Thanks!
33 votes
6 answers
27k views
Refactoring ADO.NET - SqlTransaction vs. TransactionScope
I have "inherited" a little C# method that creates an ADO.NET SqlCommand object and loops over a list of items to be saved to the database (SQL Server 2005). Right now, the traditional SqlConnection/...
4 votes
11 answers
1k views
Best Practice for Try Catch Error Handling
I'm trying to avoid returning an incorrect value when in the catch but I'm having trouble finding a better solution than this: private SecurityLevel ApiGetSecurityLevel() { try ...
4 votes
3 answers
17k views
The use of ApplicationException [duplicate]
I'd like to know if the use of ApplicationException is recommended to return application errors when a user breaks some business rule. For example: public void validate(string name, string email) { ...
8 votes
6 answers
855 views
Position of the try catch statement
I have some code that currently looks somewhat like this: public void MainFunction() { try { SomeProblemFunction(); } catch { AllFineFunction(); } } private void ...
1 vote
5 answers
8k views
try-catch for logging purposes?
According to this answer: https://stackoverflow.com/a/1722991/680026 you should only use try-catch if you really do something there besides logging: Don't catch an exception if you're only going to ...
4 votes
2 answers
10k views
How to send android app logs to remote server?
In my application, I want to send logs in case of crash to remote server. I have added try-catch block and in catch I'm sending logs to server. I want to know what all exceptions should I catch. I ...
6 votes
2 answers
3k views
Check for support of Javascript delete functionality
In Javascript you can delete an object property: var o = { x: 1, y: 2 }; var wasDeleted = delete o.x; Now o.x should be undefined and wasDeleted is true. However you can only delete native objects, ...
1 vote
3 answers
2k views
How to find out if any method is written without having try catch block
In a Visual Studio 2010 C# Project, how do I find out if any method is written without having a try-catch block? Sometimes as a code reviewer, its hard to search function/methods which are not ...
1 vote
2 answers
4k views
PDO. How to put the connection in an external file
If I want to put the connection in an external file, what part of this code should be in that external file? $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "podcast"; ...