exception

What exception should be thrown when validating results from external callbacks in .NET?

ArgumentException and ArgumentNullException are both used for validating arguments, eg. if (argument == null) throw new ArgumentNullException("argument must not be null", "argument"); What is the best equivalent for validating the results of callbacks, eg. var x = argument.GetX(); if (x == null) throw ??? ...

How can I catch all the exceptions that will be thrown through reading and writing a file?

In Java, is there any way to get(catch) all exceptions instead of catch the exception individually? ...

Replace ResourceDictionary while Storyboard is running in WPF?

I'm using multiple ResourceDictionarys to enable skinning in my WPF application. I have a button that's using WPF Toolkit's VisualStateManager to animate state changes. Great! Now, when the button is pressed, the style changes by loading a different ResourceDictionary. Now the problem comes when the button's Storyboard for transitioning...

Returning a value on exception

Why does this code not compile? It gives me the error: not all code paths return a value Code: public bool isUserProfileHashed(string username) { bool isHashed = false; MembershipUser u = null; u = Membership.GetUser(username); if (u != null) { try { u.GetPassword(); ...

Using a code for an exception. Useful?

Hi, I am not sure if Exceptions work the same way in each language, but I am using PHP and I was wondering when I'm doing something like this: if (!$this->connection[0]->query($this->query)) throw new QueryFailedException($this->connection[0]->error); Is there a need to supply a code in the second parameter? For example: if (!$this...

I don't understand why this ClassNotFoundException gets thrown

I'm executing the java binary from one of my classes, and a ClassNotFoundException gets thrown: Results of executing:/usr/bin/java -classpath "/home/geo" Geoline Error stream: Exception in thread "main" java.lang.NoClassDefFoundError: Geoline Caused by: java.lang.ClassNotFoundException: Geoline at java.net.URLClassLoader$1.run(...

MySQL stored procedure call from ASP.NET 2 throws Use Procedure bodies exception

Hi I have the following scenario. I am calling stored procedures to MySQL 5.x from my .NET 2 application. All stored procedures have parameters and they work fine with the exception of two which throw the following exception (only when deployed to production): "When calling stored procedure and 'Use Procedure bodies' is false, all param...

Logging Caught and Uncaught Exceptions?

Hi, I have been working with Exceptions lately. I think it makes sense to log uncaught Exceptions, because it greatly helps developers to take care of possible problems in the source by simply looking at Exception log. However, when an exception is dealt with, is there a need to log it any longer? Yes, to some extent. If you have "bad" ...

NSMutableArray - replacing an item causes exception...help!

I am a newbie in Obj-C. I need to learn this better so please tell me what I am doing wrong.. I have an array of Images.... at various points of exec I need to replace the last element with one of the preceding images... so the last image always replicates one of the images before. When I do the replacement, it throws an exception! If ...

Exceptions and Abstractions

When should you throw a custom exception? e.g. I have some code that connects to a server. The code that connects to the server throws an IOException when it fails to connect. In the context of the method it's called, this is fine. It's also fine in the network code. But as this represents not having a connection (and therefore not wor...

PHP try-catch blocks: are they able to catch invalid arg types?

Background: Suppose I have the following obviously-incorrect PHP: try{ $vtest = ''; print(array_pop($vtest)); }catch(Exception $exx){} For it to work with array_pop, $vtest should obviously be an array, not a string. Nevertheless, when I run this code the Warning is exhibited. I don't want that, I just want the...

Does try/finally ignore exceptions?

I have a situation where I want certain code to be executed no matter what happens, but I need exceptions to also be passed on up the stack to be handled later. Is the following: try { // code } finally { // code that must run } going to just ignore any exceptions, or will it pass them on up? My testing seems to show that they st...

How to work with unchecked exceptions?

Java has compiler checked exceptions. When I made transition to C++, I learned it doesn't feature checked exceptions. At first, I kept using exception handling, because it's a great feature. However, after a while I abandoned it, because I got into a situation every function might throw an exception. As only a small percentage of the fun...

How do I dispose an IDisposable object if the using statement throws an exception?

How can I make sure in the following code snippet that IDataReader is disposed of if ExecuteReader throws an exception? using (IDataReader rdr = cmd.ExecuteReader()) { // use it } It makes sense to me that the using syntatic sugar does not call Dispose (since there is no instance to call it on). However, how can I be sure that the...

How can I avoid the general Exception thrown by the Server-class in Jetty?

Jetty can be used as a library to embed a servlet-server into your application. To do that, you create an instance of the class Server and call start at some point. This method throws Exception. Catching or throwing a pure Exception (not a specialized subclass) is bad style. Does anyone know, how I can avoid this and get a Jetty-server i...

Defining custom exception in a module in Rails

Hi! I've created a custom module (which currently only defines a new Exception class), and put it under lib/lib_th.rb module LibTH module Error IDNotFound = Class.new end end I should not need to require/include the module in my code, as it should be automatically loaded, since it follows the conventional naming rules...

Exception slicing - is this due to generated copy constructor?

I've just fixed a very subtle bug in our code, caused by slicing of an exception, and I now want to make sure I understand exactly what was happening. Here's our base exception class, a derived class, and relevant functions: class Exception { public: // construction Exception(int code, const char* format="", ...); virtual ~Except...

Find module name of the originating exception in Python

Example: >>> try: ... myapp.foo.doSomething() ... except Exception, e: ... print 'Thrown from:', modname(e) Thrown from: myapp.util.url In the above example, the exception was actually thrown at myapp/util/url.py module. Is there a way to get the __name__ of that module? My intention is to use this in logging.getLogger functio...

Exceptional Magic

According to the DimusWare site, Exceptional Magic was tested through Delphi version 2006. Does Exceptional Magic work with Delphi 2007? If not, does Delphi 2007/2009 provide the same or very similar features to Exceptional Magic? ...

How should I store data inside custom exceptions?

When dealing with custom exceptions, I usually inherit from Exception and then add some fields/properties to my exception class to store some additional info: public class MyException : Exception { public int ErrorCode{get;set;} public MyException() {} } In the above example, the ErrorCode value is stored in the exception...