exception-handling

Using Exceptions exceptionally

Hi guys, This is a refactoring question. try { string line = GetFirstLineFromFile(); //Gets first line from a text file, this line would be a number. int value = ConvertToInteger(line); // Gets the integer value from the string. int result = DivideByValue(value); // Divides some number with the value retrieved. } catch(Exception ...

Is there really a performance hit when catching exceptions

edit: Someone had added the C# keyword. I am NOT talking about C#, just exceptions in general. Specifically, exceptions in compiled languages like C++ and D; though C# was also in my mind. I asked a question about exceptions and I am getting VERY annoyed at people saying throwing is slow. I asked in the past How exceptions work behind ...

Does a exception with just a raise have any use?

For example, here is some code from django.templates.loader.app_directories.py.[1] try: yield safe_join(template_dir, template_name) except UnicodeDecodeError: # The template dir name was a bytestring that wasn't valid UTF-8. raise If you catch an exception just to re raise it, what purpose does it serve? [1] http://code....

Exception handling with multiple forms

I'm seeing different behavior with exceptions being caught or not being caught when I am debugging vs. when I am running a compiled .exe. I have two forms (Form1 and Form2). Form1 has a button on it which instantiates and calls ShowDialog on Form2. Form2 has a button on it which intentionally produces a divide by zero error. When I'm...

Filter on exception text in elmah

Is there a way to filter exceptions in elma using the exception message? Examples: "System.Web.HttpException: Request timed out." I don't want to filter out all HttpException, but only the timed-out requests. "System.Web.HttpException: Maximum request length exceeded." What I don't want to do is write own code for that. So is it possib...

How do I ignore exceptions in F#

During normal program's execution an exception may occur. In case I'm aware of it and just want to ignore it — how do I achieve this in F#? Here is my code, which compiles with a warning: let sha = new SHA1CryptoServiceProvider() let maxLength = 10000 let fileSign file = let fs = File.OpenRead(file) let mutable res = (0L, [|0...

ASP.NET health monitoring and performance counter

Hi all, Looking for best practice here. I know that there are multiple ways to do logging and exception handling in asp.net, for example, using enterprise library, log4net or even post sharp for AOP style logging. However, I haven't seen that many logging/exception handling articles related to health monitoring and performance counter...

Java find the first cause of an exception

I need to check if an exception is caused by some database problem. I receive an Exception and check if its cause contains the "ORA" string and return that (something like "ORA-00001"). The problem here is that the exception I receive is nested inside other exceptions so if I don't find if it's an oracle exception I have to check into th...

General Exception in Java

Hi All, I am looking to throw a general Exception in Java. The "situation" is basically if an empty line is encountered, an exception is thrown and the blank line ignored. Now, I come from a C# background so I would just throw a normal Exception. In Java, is there one? I can't seem to find it. I know I could assert, but would this so...

Catch Javascript syntax errors while using YUI3

I'm using slightly modified sample code provided by the YUI team. When my source responds with something other than JSON (or just has a JSON syntax error) my browser (Safari) aborts script processing, preventing me from notifying the user there was a problem. I'm definitely no JS guru, so this code may be a lot uglier than it has to be....

Java: Try-Catch-Continue?

Let's say I can a set of statements: try { String a = getProperty("a"); String b = getProperty("b"); String c = getProperty("c"); } catch(Exception e) { } Now, lets say property b was not found and the function throws an exception. In this case, how would I just continue or perhaps set b to null without having to write a try-ca...

Centralized Exception handling for Eclipse plug-in

Hello, At first I thought this would be question often asked, however trying (and failing) to look up info on this proved me wrong. Is there a mechanism in Eclipse platform for centralized exception handling of exceptions? For example... You have plug-in project which connects to a DB and issues queries, results of which are used to p...

How to log exceptional situations in C++?

When writing a function, my implementation very frequently looks like this: Call a subfunction If this subfunction fails to execute (because of an exceptional situation): log this failure and abort the current function Otherwise continue calling other subfunctions, which in turn can fail A crucial part is the logging. Every function ...

Shutdown exception handling for Win32/C++

I have a process that handles exceptions great. It calls: _set_se_translator(exception_trans_func); SetUnhandledExceptionFilter(UnhandledExceptionFilterHandler); _set_purecall_handler(purecallHandler); set_terminate(terminateHandler); set_unexpected(unexpectedHandler); _set_invalid_parameter_handler(InvalidParameterHandler); atexit(ex...

Exception or Error Code Enum

Recently I'm refactoring a .net program which will use a custom usb device. The device comes with a dll for communication. The dll is written in c and by checking the header, it defines a set of error return codes. The first step to comminicate with the device is to open the device. In dll, the open function looks like this: // retu...

Using log4j with Web container (part of the J2EE server).

When our application throws errors that we catch, we put the message and stacktrace in a log file created specifically for our application (myapp.log). For example: public class SomeClass { OurLogger log = OurLogger.getLogger ("myapp", SomeClass.class); public void someMethod { try { //code } catch (DataAcce...

Passing Exception Types down through a menu.

So I've come across this problem and I can't seem to solve it. Basically I've got a menu of tests, it can be of arbitrary depth, it's just a way of organizing tests and at the lowest level has specific test-cases. As it stands right now everything seems to work, however I'd like to implement a system where you can specify an exception ...

is it good to catch error in DAO?

public boolean checkInd() { int dis_ind = 2; HashMap parmMap = new HashMap(); //line below can generate errors getSqlMapClientTemplate().queryForList("authentication.checkInd", parmMap); List results = (List) parmMap.get("Result0"); HashMap resultMap; if (result.size()>0) resultMap = (HashMap)resultMap...

Should I use an exception in this case?

I've designed a simple program that has a counter class and inside that counter class I have methods that increment the count, deincrement the count, and so on. I then present a menu to the user and have them enter their choice, ex. enter 1 for option one, etc. Well, I don't ever want the count to be negative, so to handle this I had my...

find exception type

I have created custom exception class public class Web2PDFException : Exception { public Web2PDFException(string message, Exception innerException) : base(message, innerException) { } } in my application I want to find out is throw exception is my custom exception or not. try { } catch (Exception err) { ...