All Questions

232
votes
15answers
78968 views

Why is "except: pass" a bad programming practice?

I often see comments on other Stack Overflow questions about how the use of except: pass is discouraged. Why is this bad? Sometimes I just don't care what the errors, are and I want to just continue w...
182
votes
4answers
109336 views

How to write trycatch in R

I want to write trycatch code to deal with error in downloading from web. url <- c( "http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html", "http://en.wikipedia.org/wiki...
80
votes
14answers
63969 views

Catching java.lang.OutOfMemoryError?

Documentation for java.lang.Error says: An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch But as java.lang.Error is a subc...
152
votes
20answers
59277 views

Why are empty catch blocks a bad idea?

I've just seen a question on try-catch, which people (including Jon Skeet) say empty catch blocks are a really bad idea? Why this? Is there no situation where an empty catch is not a wrong design deci...
409
votes
15answers
158744 views

Why catch and rethrow an exception in C#?

I'm looking at the article C# - Data Transfer Object on serializable DTOs. The article includes this piece of code: public static string SerializeDTO(DTO dto) { try { XmlSerializer xmlSe...
87
votes
9answers
70794 views

C# catch a stack overflow exception

I got a recursive call to a methode that throw a stack overflow exception. The first call is surrounded by a try catch block but the exception is not caught. Do the stack overflow exception behave i...
86
votes
7answers
21933 views

Better to 'try' something and catch the exception or test if its possible first to avoid an exception?

Should I test if something is valid or just try to do it and catch the exception? Is there any solid documentation saying that one way is preferred? Is one way more pythonic? For example, should I...
191
votes
10answers
41428 views

Do try/catch blocks hurt performance when exceptions are not thrown?

During a code review with a Microsoft employee we came across a large section of code inside a try{} block. She and an IT representative suggested this can have effects on performance of the code. In ...
156
votes
14answers
243328 views

How using try catch for exception handling is best practice

while maintaining my colleague's code from even someone who claims to be a senior developer, I often see the following code: try { //do something } catch { //Do nothing } or sometimes they writ...
499
votes
8answers
332065 views

Can I catch multiple Java exceptions in the same catch clause?

In Java, I want to do something like this: try { ... } catch (IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException e) { someCode(); } ...ins...

Previous Next