exception

Unhandled Exception Handler in .NET 1.1

I'm maintaining a .NET 1.1 application, and one of the things I've been tasked with is making sure the user doesn't see any unfriendly error notifications. I've added handlers to Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, which do get called. My problem is that the standard CLR error dialog is still disp...

How do I fix 'Unprocessed view path found' error with ExceptionNotifier plugin in rails 2.1?

After upgrading a rails 1.2 website to 2.1, the ExceptionNotifier plugin no longer works, complaining about this error: ActionView::TemplateFinder::InvalidViewPath: Unprocessed view path found: "/path/to/appname/vendor/plugins/exception_notification/lib/../views". Set your view paths with #append_view_path, #prepend_view_path, or #vie...

Exceptions in C++

Exceptions in C++ don't need to be caught (no compile time errors) by the calling function. So it's up to developer's judgment whether to catch it using try/catch (unlike in Java). Is there a way one can ensure that the exceptions thrown are always caught using try/catch by the calling function? ...

Reducing duplicate error handling code in C#?

I've never been completely happy with the way exception handling works, there's a lot exceptions and try/catch brings to the table (stack unwinding, etc.), but it seems to break a lot of the OO model in the process. Anyway, here's the problem: Let's say you have some class which wraps or includes networked file IO operations (e.g. read...

IllegalArgumentException or NullPointerException for a null parameter?

I have a simple setter method for a Java property and null is not appropriate for this particular property. I have always been torn, in this situation: should I throw an IllegalArgumentException, or a NullPointerException? From the javadocs, both seem appropriate. Is there some kind of understood standard? Or is this just one of thos...

Why can't I use a try block around my super() call?

So, in Java, the first line of your constructor HAS to be a call to super... be it implicitly calling super(), or explicitly calling another constructor. What I want to know is, why can't I put a try block around that? My specific case is that I have a mock class for a test. There is no default constructor, but I want one to make the ...

Performance Considerations for throwing Exceptions

I have come across the following type of code many a times, and I wonder if this is a good practice (from Performance perspective) or not: try { ... // some code } catch (Exception ex) { ... // Do something throw new CustomException(ex); } Basically, what the coder is doing is that they are encompassing the exception in a ...

I can't get my debugger to stop breaking on first-chance exceptions

I'm using Visual C++ 2003 to debug a program remotely via TCP/IP. I had set the Win32 exception c00000005, "Access violation," to break into the debugger when thrown. Then, I set it back to "Use parent setting." The setting for the parent, Win32 Exceptions, is to continue when the exception is thrown. Now, when I debug the program, it ...

With Lucene: Why do I get a Too Many Clauses error if I do a prefix search?

I've had an app doing prefix searches for a while. Recently the index size was increased and it turned out that some prefixes were too darned numerous for lucene to handle. It kept throwing me a Too Many Clauses error, which was very frustrating as I kept looking at my JARs and confirming that none of the included code actually used a b...

Final managed exception handler in a mixed native/managed executable?

I have an MFC application compiled with /clr and I'm trying to implement a final handler for otherwise un-caught managed exceptions. For native exceptions, overriding CWinApp::ProcessWndProcException works. The two events suggested in Jeff's CodeProject article, Application.ThreadException and AppDomain.CurrentDomain.UnhandledException,...

Catching unhandled exceptions in ASP.NET UserControls

I'm dynamically loading user controls adding them to the Controls collection of the web form. I'd like to hide user controls if they cause a unhandled exception while rendering. So, I tried hooking to the Error event of each UserControl but it seems that this event never fires for the UserControls as it does for Page class. Did some ...

How to trace COM objects exceptions?

I have a DLL with some COM objects. Sometimes, this objects crashes and register an error event in the Windows Event Log with lots of hexadecimal informations. I have no clue why this crashes happens. So, How can I trace those COM objects exceptions? ...

C# - CryptographicException: Padding is invalid and cannot be removed

I needed some simple string encryption, so I wrote the following code (with a great deal of "inspiration" from here): // create and initialize a crypto algorithm private static SymmetricAlgorithm getAlgorithm(string password) { SymmetricAlgorithm algorithm = Rijndael.Create(); Rfc2898DeriveBytes rdb = new Rfc2898...

A ThreadStateException occures when trying to restart a thread

From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread. The code in question is as follows: // Make sure the thread is done stopping while (this.mThread.ThreadState == ThreadState.Running) { Thread.Sleep(0); } // Respawn a thread if the current one is stopped or doesn't exist if (this.mThread...

Prevent WebBrowser control from swallowing exceptions

I'm using the System.Windows.Forms.WebBrowser, to make a view a la Visual Studio Start Page. However, it seems the control is catching and handling all exceptions by silently sinking them! No need to tell this is a very unfortunate behaviour. void webBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e) { // WebBrowser.N...

How do I log uncaught exceptions in PHP?

I've found out how to convert errors into exceptions, and I display them nicely if they aren't caught, but I don't know how to log them in a useful way. Simply writing them to a file won't be useful, will it? And would you risk accessing a database, when you don't know what caused the exception yet? ...

Do you write exceptions for specific issues or general exceptions?

I have some code that gives a user id to a utility that then send email to that user. emailUtil.sendEmail(userId, "foo"); public void sendEmail(String userId, String message) throws MailException { /* ... logic that could throw a MailException */ } MailException could be thrown for a number of reasons, problems with the email add...

How Do You Communicate Service Layer Messages/Errors to Higher Layers Using MVP?

I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP architecture because I'm sick of Winforms and wanted something that had a better separation of concerns. So with MVP, the Presenter handles events raised by the View. Here's some code that I have in place to deal with the creation of users: public class Crea...

Is it really that bad to catch a general exception?

Whilst analysing some legacy code with FXCop, it occurred to me is it really that bad to catch a general exception error within a try block or should you be looking for a specific exception. Thoughts on a postcard please. ...

Configure a Java Socket to fail-fast on disconnect?

Hi, I have a listening port on my server that I'm connecting to using a Java class and the Socket interface, i.e. Socket mySocket = new Socket(host,port); I then grab an OutputStream, decorate with a PrintWriter in autoflush mode and I'm laughing - except if the listening port closes. Then I get tcp4 0 0 *.9999 ...