Linked Questions
26 questions linked to/from Best practices for exception management in Java or C#
11 votes
4 answers
17k views
What is the Best practice for try catch blocks to create clean code? [duplicate]
Possible Duplicate: Best practices for exception management in JAVA or C# I've read a question earlier today on stackoverflow and it made me think about what is the best practice for handling ...
0 votes
3 answers
4k views
C# and asp.net error handling best practices? [duplicate]
Possible Duplicate: Best practices for exception management in JAVA or C# I am using class libraries and I try to put maximum code in class libraries so that it can be reused in other projects. ...
770 votes
21 answers
365k views
Understanding checked vs unchecked exceptions in Java
Joshua Bloch in "Effective Java" said that Use checked exceptions for recoverable conditions and runtime exceptions for programming errors (Item 58 in 2nd edition) Let's see if I understand ...
15 votes
11 answers
4k views
Which is better/more efficient: check for bad values or catch Exceptions in Java
Which is more efficient in Java: to check for bad values to prevent exceptions or let the exceptions happen and catch them? Here are two blocks of sample code to illustrate this difference: void ...
17 votes
5 answers
21k views
Throwing generic Exception discouraged?
Why is it discouraged to throw a generic (java.lang.Exception) exception, when it is usually sufficient to handle most conditional failures within a method? I understand that if a method could throw ...
13 votes
4 answers
33k views
How to propagate an exception in java
I am a C programmer and just learning some java recently because I am developing one android application. Currently I am in a situation. Following is the one. public Class ClassA{ public ClassA(); ...
22 votes
6 answers
3k views
What should be included in the state-of-the-art error and exception handling strategy? [closed]
I understand that this is a very broad question, but a short “it depends” kind of answer will not be accepted. Strategies are born to deal with broad issues. What issues should an application designer ...
9 votes
5 answers
30k views
What is the best way to return error message from function?
If face a logic error error such (Expired user, invalid ID), then what is the best way to tell the parent method of this error from the following : 1- Throwing customized exception like the following ...
9 votes
4 answers
14k views
Catching versus Throwing Exceptions in Java [duplicate]
So I have two general questions about java in general. The first is when would one use a try/catch in the body of the method versus using throws exception in declaring the method? Here is a little ...
9 votes
6 answers
3k views
Are try/catch for every single statement that throws an exception considered an anti-pattern?
I am currently reviewing a colleagues Java code, and I see a lot of cases where every single statement that may throw an exception being encapsulated in its own try/catch. Where the catch block all ...
5 votes
4 answers
4k views
How to combine logging with an exception handling chain?
Suppose I have the following code: void foo() { /* ... */ try { bar(param1); } catch (MyException e) { /* ??? */ } } void bar(Object param1) throws MyException { /...
2 votes
6 answers
4k views
Avoiding multiple try catch
In my application i have 100 classes and each class contains 4 methods each. I am using try catch for exception handling. I write try catch in each method , then there will be 400 try catch statement ...
5 votes
3 answers
9k views
Best practices in handling java exceptions
I am beginning to learn Java and writing my first utility classes in java which are supposed to go in production. I am somewhat lost when it is coming to dealing with exceptions. Is there some ...
1 vote
5 answers
2k views
Exception handling best practices revised
I have a piece of code where I capture all exceptions and throw one generic exception at the end. Something like this: try { // do something here } catch (Whatever e) { throw new MyException(e....
2 votes
5 answers
2k views
C# SmtpClient.Send() - Any alternative (or companion) to handling the exception?
(Long time reader of SO, first time asking a q. I'm quite new to C# having been in the PHP/Ruby/Python world for many years so I apologise if this is a dopey question.) I'm doing some maintenance on ...