exception-handling

An exception that cannot be caught?

Hey, I have the following code in my files: In Class Customer.Page: Try If Not SiteContent.CurrentUser(False) Is Nothing Then If Not SiteContent.CurrentUser(False).IsAdministrator OrElse SiteVariables.CustomerMode Then SiteContent.PageViewManager.Create(New List(Of Control)) End If Else Site...

How do I handle an exception in an ASP.NET MVC controller factory

I have an ASP.NET MVC 2 application with a custom StructureMap controller factory to handle dependency injection for my controllers: public class StructureMapControllerFactory : DefaultControllerFactory { public override IController CreateController(RequestContext context, string controllerName) { Type controllerType = b...

Java: why can't I throw an exception in Comparator?

The direct answer is because Comparator.compares interface is specified as such that it does not throw exceptions. But why is that? Or to put it different: My Comparator must depend on a function which can throw an exception. In theory, that should not happen. But if it happens, I want that it breaks out of the whole function where I am...

Using a try/catch to retry the same method

I have a class whose methods require that a certain class field exists correctly. That class field is set in the constructor and it's read from a config file, and it may or may not get the correct data from that config file. If the data is incorrect, it will have the wrong data in the class field and the class method will throw an except...

C++ re throw Exception gives error

I'm trying to catch a 'specific' exception (FormatException^ or OverflowException^) and then re throw it and catch it in the 'general' exception (Exception^) catch block. When run, I give it a format exception through input. I then get this error in a dialog box: "An unhandled exception of type 'System.FormatException' occurred in Futu...

Custom Exceptions in Clojure?

I've been trying to create a user-defined exception in Clojure, and have been having all sorts of problems. I tried the method outlined here: http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#User-Defined_Exceptions (gen-and-load-class 'user.MyException :extends Exception) But that doesn't seem to work in Clojure 1.2 (or I'm...

Java: How to throw an Execption to the method caller inside a try catch body?

Hi, When I have a method like this: public static void foo(String param) throws IOException { try { // some IOoperations if (param.isEmpty()) { throw new IOException("param is empty"); } // some other IOoperations } catch (Exception e) { /* handle some poss...

Why doesn't Python's `except` use `isinstance`?

The Python documentation for except says: For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is “compatible” with the exception. An object is compatible with an exception if it is the class or a base class of the exception object, [...] Why...

IOException inside print or println

Most of the IO operation requires try catch block or throws . Why is try catch or throws not required for System.out.print or println. If there is any exception inside these methods how would i know whats the exception and how to catch it. ...

Firing Keypress for a command prompt window from .net app

I have a .net console application that runs a method called RunBatch() on 10 threads. The method creates a process object and calls a .bat file. The .bat file runs an instance of a tool called Lualatex - which is an exe that converts .tex files to .pdf files- and passes it the path of the .tex file to be converted. (e.g, Lualatex.exe "F...

[Android] My "MyException" which shows Toast causes trouble while thrown in threads. How should I reorganize Exception handling?

I have written my own Exception (MyException) and implemented Logging and showing Error Messages in Form of Toasts. Here is the shortform of it... public class MyException extends Exception { public MyException(String msg) { Looper.prepare(); Toast.makeText(Controller.getInstance().getApplicationContext(), msg , Toast.L...

Design time exception not caught in .Net Winforms

I have a form that is used at design-time to configure various properties. I've tried two ways to do a form-level catch all exception: (1) I add a handler to Application.ThreadException in the constructor. (2) I wrap the Show method, of the form, in a Try/Catch block Both of these work at run-time when I test by adding a property gri...

handle unhandled exception

Hi all, I have a Ria service to call logic code. I want to write try catch block in every logic funtion to provide ways to handle unhandeled exceptions. try { //something } catch(BussinessException e) { //save e.info to database } But I don't want to write this block code everywhere in my logic, and I don't want to put the exception ...

TypeLoadException hiding inner exception

Hi I'm using Compact Framework 3.5 / VS2008. I'm getting really odd behavior with TypeLoadException. The following code throws this error. The reason is a problem with the database connection. However for some unknown reason this inner exception is lost and is not contained in the TypeLoadException. try { settingsFromDb = Settings...

Do you really need the 'finally' block

There are 3 permutations of a try...catch...finally block in java. try...catch try...catch...finally try...finally Once the finally block is executed, control goes to the next line after the finally block. If I remove the finally block and move all its statements to the line after the try...catch block, would that have the same effec...

Throw a C# exception of the same type as that caught ?

Hi, why (if at all) is this a bad idea ? class Program { static void Main(string[] args) { try { throw new NotImplementedException("Oh dear"); } catch (Exception ex) { throw NewException("Whoops", ex); } } // This function is the salient bit here public static Exception NewExcept...

Catch all exception good or bad?

I've seen in multiple projects a kind of catch all exception to catch all unexpected exception so the app won't crash, i see this usually with : AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(myUnexpectedExhandler); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(threadE...

What's a good general way of catching a StackOverflow exception in C#?

If I have a method that I know could potentially recurse infinitely, but I can't reliably predict what conditions/parameters would cause it, what's a good way in C# of doing this: try { PotentiallyInfiniteRecursiveMethod(); } catch (StackOverflowException) { // Handle gracefully. } Obviously in the main thread you can't do this, b...

PHP: Custom error handler for PDO?

I am attempting to try to do something useful with PDO exceptions other than display them, but I cannot find for the life of me how to use an error handler (set_error_handler) or anything custom to deal with PDOs exceptions. Now I am using try..catch blocks of course the catch the exception, do I implement a custom error handler in the...

Exception handling in ThreadPools

I have a ScheduledThreadPoolExecutor that seems to be eating Exceptions. I want my executor service to notify me if a submitted Runnable throws an exception. For example, I'd like the code below to at the very least print the IndexArrayOutOfBoundsException's stackTrace threadPool.scheduleAtFixedRate( new Runnable() { public void...