exception-handling

Force break on any exception thrown in program

When coding in C# I like not to handle exceptions because it makes it easier to figure out where and why things went wrong. However, I can't give anyone a program that doesn't handle exceptions. Can I somehow force Visual Studio to break on every exception, including those thrown inside try/catch blocks? ...

Properly handling exceptions thrown in a thread or via the WPF dispatcher.

When a thread throws an exception that is unhandled, it terminates. What is the proper way to handle exceptions thrown on threads and how to propogate relevant exception data to other parts of the code that would need to subscribe to notifications? Is there an INotifyThreadPoorlyDesigned interface that I missed somewhere? Same applies ...

Getting a blank screen during staging errors in Rails/Passenger

I usually get the typical red error message when errors occur in my staging environment but lately the errors have been resulting in a blank screen. Is there a way to explicitly tell Rails to raise the typical error message in specific environments? ...

How does wrapping an unsafe python method (e.g os.chdir) in a class make it thread/exception safe?

In the question How do I "cd" in python, the accepted answer recommended wrapping the os.chdir call in a class to make the return to your original dir exception safe. Here was the recommended code: class Chdir: def __init__( self, newPath ): self.savedPath = os.getcwd() os.chdir(newPath) def __del__( self ): ...

Exceptions: redirect or render?

I'm trying to standardize the way I handle exceptions in my web application (homemade framework) but I'm not certain of the "correct" way to handle various situations. I'm wondering if there is a best practice from UI/ user-friendly point of view. User logs into application and opens two tabs showing the same screen. On one tab they ...

Handling an exception in Objective C and figuring our what it means

I send some data from my App to a web service and it replies. I start that process by clicking a button in the UI. It works fine, until I start trying to do that really fast. If I do that fast it breaks and I get this message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSXMLParserInfo leng...

Java: Exceptions

Hi, Why is this code correct: try { } catch(ArrayOutOfBoundsException e) { } and this wrong: try { } catch(IOException e) { } This code is wrong because in the try-body never an IOException is thrown, but in the first body there is also never throw a ArrayOutOfBoundsException. And the first code-piece is correct. Why?? Can I ...

How to wrap built-in methods in Python? (or 'how to pass them by reference')

I want to wrap the default open method with a wrapper that should also catch exceptions. Here's a test example that works: truemethod = open def fn(*args, **kwargs): try: return truemethod(*args, **kwargs) except (IOError, OSError): sys.exit('Can\'t open \'{0}\'. Error #{1[0]}: {1[1]}'.format(args[0], sys.exc_inf...

Exception message (Python 2.6)

If I want to open binary file (in Python 2.6), that doesn't exists, program exits with an error and prints this: Traceback (most recent call last): File "C:\Python_tests\Exception_Handling\src\exception_handling.py", line 4, in <module> pkl_file = open('monitor.dat', 'rb') IOError: [Errno 2] No such file or directo...

Exception Handling in HttpHandler ASHX file

I'm using ASHX file to creating images in a dynamic way. I added a line of code to throw an exception in my ashx file. if I browse to ashx file directly, my application_error in global.asax is working fine to handle the error. my problem is application_Error is not working when I use this handler in another page. like in show.aspx if I...

Jython exception handling within loops

Hi, I am using Marathon 2.0b4 to automate tests for an application. A shortcoming of wait_p, one of the script elements provided by Marathon, is that its default timeout is hardcoded to be 60 seconds. I needed a larger timeout due to the long loading times in my application. [I considered patching Marathon, but didn't want to maintain ...

How to use rspec's should_raise with any kind of exception?

I'd like to do something like this: some_method.should_raise <any kind of exception, I don't care> How should I do this? some_method.should_raise exception ... doesn't work. ...

Pattern to catch exception from sections of code (while not making eyes bleed)

I have a section of code that looks like this: try { classVar = functionCall(input, sEnum.First); classVar = functionCall(input, sEnum.Second); classVar = functionCall(input, sEnum.Third); } catch (Exception ex) { Debug.Assert(false, ex.ToString()); } However my exception dosent show which specific call it came from. The sta...

Hibernate Validator Exceptions

I'm using Hibernate Validator in an application with EJB and Spring MVC. I'm using JBoss 5, Hibernate 3 and Spring MVC version 3. I'd like to try and catch validation exceptions at Spring Exception Resolver level and generate an error message based on the InvalidStateException message. I don't want to put exception handling logic in t...

what is difference between Exception handling Application block & Exception handling

what is difference between Exception handling Application block & Exception handling in regular dot net classes ? i don't think it is beneficial to use of Exception handling Application block. What is exact use of that block ?? ...

is there a way to both catch and throw an exception

I have a method that is going to the DB so all our JDBC stuff in the DAO method is inside a try/catch block. It is catching SQLException When I write a test case against this method and if a SqlException occurs then my testcase does not say 'caused an error'. it just goes on its merry way. However, If I dont catch the SqlException i...

handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There're 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status Error code and message directly when an exception occurs Response.Redirect to the custom error page ...

Java: How would I write a try-catch-repeat block?

I am aware of a counter approach to do this. I was wondering if there is a nice and compact way to do this. ...

Why is exception handling bad?

I've heard this on the Internet. For instance, Google's Go language has no exceptions as a design choice, and Linus of Linux fame has called exceptions crap. I am just wondering why? ...

proper way to read user input from command line in java

I was hoping to get some opinions regarding best practices and comments on the way I read user input from the command line. Is there a recommended way to do this, am I using the try/catch blocks properly? My example here works fine, but would still like to hear if there is a 'cleaner' way to do this. Many thanks. For example are he retu...