exception

Why should I not wrap every block in "try"-"catch"?

I have always been of the belief that if a method can throw an exception then it is reckless not to protect this call with a meaningful try block. I just posted 'You should ALWAYS wrap calls that can throw in try, catch blocks.' to this question and was told that it was 'remarkably bad advice' - I'd like to understand why. Thanks! ...

Better exception for non-exhaustive patterns in case

Is there a way to get GHCi to produce better exception messages when it finds at runtime that a call has produced value that does not match the function's pattern matching? It currently gives the line numbers of the function which produced the non-exhaustive pattern match which though helpful at times does require a round of debugging w...

WINAPI SetLastError versus C++ Keword Throw

What is the difference between the WINAPI SetLastError() and the C++ keyword throw? For example, are SetLastError(5); and throw 5; the same? ...

Silverlight preview XAML file exception

I have upgraded my Silverlight project from 2 to 3 and uses VS 2008. When I open the XAML-file preview in VS 2008 an exception occured: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at MS.Internal.XcpImports.RenderTargetBitmapRenderNative(IntPtr nativePtr, IntPtr element, Int3...

Windows: Does something temporarily grab the com ports on startup?

I have a WPF/C# app that is launched as part of the "Startup" group on a Windows Embedded Standard machine. One of the first things the app does (in its static App() method) is create a new SerialPort object for COM1. COM1 is a hardwired serial port, not a USB virtual port or anything like that. My problem is that every so often (maybe ...

Can I enable/disable breaking on Exceptions programatically?

I want to be able to break on Exceptions when debugging... like in Visual Studio 2008's Menu Debug/Exception Dialog, except my program has many valid exceptions before I get to the bit I wish to debug. So instead of manually enabling and disabling it using the dialog every time is it possible to do it automatically with a #pragma or som...

Preventing the "[YourProgramName] has stopped working" dialog on unhandled exceptions.

I have a WinForm application, with some dependencies on an external library that can on occasion cause an exception outside of the running threads context. As it stands now, this is completely OK behavior ( well, except of course the exception ) and we wired up AppDomain.CurrentDomain.UnhandledException to simply restart the program. ...

Condition checking vs. Exception handling

When is exception handling more preferable than condition checking? There are many situations where I can choose using one or the other. For example, this is a summing function which uses a custom exception: # module mylibrary class WrongSummand(Exception): pass def sum_(a, b): """ returns the sum of two summands of the same ...

Python raises a KeyError (for an out of dictionary key) even though the key IS in the dictionary

I'm getting a KeyError for an out of dictionary key, even though I know the key IS in fact in the dictionary. Any ideas as to what might be causing this? print G.keys() returns the following: ['24', '25', '20', '21', '22', '23', '1', '3', '2', '5', '4', '7', '6', '9', '8', '11', '10', '13', '12', '15', '14', '17', '16', '19', '18'] ...

For loop index out of range ArgumentOutOfRangeException when multithreading

I'm getting some strange behavior... when I iterate over the dummyText List in the ThreadTest method I get an index out of range exception (ArgumentOutOfRangeException), but if I remove the threads and I just print out the text, then everything works fine. This is my main method: public static Object sync = new Object(); static void Ma...

How can I show SQL Server LOGS (2005)

Hello, I'm trying to track the error thrown by SQL Server 2005. The problem is SQL Server reports it in my native language so it's hard for me to google it. I think that the core issue would be avialable in English in SQL Server LOGS. I'm running SQL Server Management Studio Express, going to "Management" node, and then SQL Server Log...

System.AccessViolationException: Attempted to read or write protected memory.

I get the following exception when I try to "find and replace" in a Word 2007 working on Windows Vista or Windows 7. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Microsoft.Office.Interop.Word.Find.Execute(Object& FindText, Objec...

Store PHP Exceptions in array

Hi everyone, I am really not sure if this is the right way to go, since exceptions is really a fresh subject to me. Is it possible to catch multiple exceptions (let the execution of the script continue) and then store the exceptions in a array to be able to return all exceptions caused? By that said, it would be awesome to be able to u...

Does everything after my try statement have to be encompassed in that try statement to access variables within it?

I'm learning java and one thing I've found that I don't like, is generally when I have code like this: import java.util.*; import java.io.*; public class GraphProblem { public static void main(String[] args) { if (args.length < 2) { System.out.println("Error: Please specify a graph file!"); ...

Java w/ SQL Server Express 2008 - Index out of range exception

Hi! I created a stored procedure in a sql express 2008 and I'm getting the following error when calling the procedure from a Java method: Index 36 is out of range. com.microsoft.sqlserver.jdbc.SQLServerException:Index 36 is out of range. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java...

how to handle delete by illegal address

Suppose we have a situation like this. Suppose instead of "p = " we called some function(written by someone which invalidate our pointer). How to handle this problem? How to protect code from crashes? I know about and use boost smart pointers. But what to do if we have this situation. struct Test { int a; int b; int c; }; T...

[WPF] ExceptionValidationRule doesn't react to exceptions...

Hi, I have an ExceptionValidationRule on my TextBox: <Window.Resources> <Style x:Key="textStyleTextBox" TargetType="TextBox"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Err...

Which exceptions do you catch when you don't specify an exception class in ruby?

Which exceptions are you catching when you don't specify an exception class like this: begin # do something rescue puts "Exception!" end ...

Why we don't have to add try-catch to a RuntimeException ?

I want to ask why we don't have to add try-catch block to a RuntimeException while we should do that with other exceptions? I mean like : public class Main { public static void main(String[] args) { throw new RuntimeException(); } } Edit : when I say : throw new RuntimeException(); it is so clear that there is an exce...

Why there is no scoped locks for multiple mutexes in C++0x or Boost.Thread?

C++0x thread library or Boost.thread define non-member variadic template function that lock all lock avoiding dead lock. template <class L1, class L2, class... L3> void lock(L1&, L2&, L3&...); While this function avoid help to deadlock, the standard do not includes the associated scoped lock to write exception safe code. { std::l...