try-catch

Error with catching std::runtime_error as std::exception

Hello, we have a funny problem with try catch and std::runtime_error. Can someone explain to me why this is returning "Unknown error" as output ? Thanks very much for helping me ! #include "stdafx.h" #include <iostream> #include <stdexcept> int magicCode() { throw std::runtime_error("FunnyError"); } int funnyCatch() { try{ ...

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...

Javascript: try/catch return statement

How a return statement inside a try/catch block works? function example() { try { return true; } finally { return false; } } I'm expecting the output of this function to be "true", but instead is "false"! ...

Can someone cite a good reference for programming with exceptions?

I prefer to have the "rc" error-code return style of error management. I agree that this presents challenges that are better served by throw-catch, however, I still feel that I am not designing and implementing in a style that is clean and maintainable. So, I am looking for a good book that discusses the pattern and is not simply a ref...

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...

Server.Transfer in Try-catch :Thread abort exception

What is the equivalent of Response.Redirect("abc.aspx",false) when i use Server.Transfer instead of Response.Redirect.I use false as the second param of Response.Redirect to stop receiving the ThreadAbort exception in a try catch block I want to get rid of the Thread.Abort exception when i use Server.Transferis in a try catch block....

Exceptions not caught in release build (WinForm desktop app, C#, VS 2010)

I developed a desktop application, it's almost done but still contains some bugs which I'm eliminating. I use a general [try...catch] block wrapped around my application [STAThread] static void Main() { try { program = new Program(); // ... } catch (Exception x) { // ... MessageBox.Show( ...

how to show exception variable value in alert box in asp.net using C#

i have the code... try { do something.. } catch(Exception ex) { Response.Write("<script>alert('"+ex+"')</script>"); } but the alert box is not displaying... if i use the code. try{do some thing} catch (Exception ex) { Response.Write("<script>alert(\"an error occur\"...

which is more efficient?? using is object and or try catch

which is more efficient/better code. to use is object and then unbox if it is that type of object?? or use try catch WizardStep parentWizardStep; try { parentWizardStep = (WizardStep)this.Parent; } catch { throw new Exception("Unable to cast parent control to this type."); } OR THIS: WizardStep parentWizardStep; ...

error in Delphi loadlibrary()

i have given a chance to my software user to select dll from openfile dialog.(so my user can download dlls form my website and use it with the main project ). everything is working fine and it can even find that dlls is provided by me or selected an invalid dll.but the problem raises if the user selects a renamed file(eg : apple.txt file...

loss exception in block catch

I run this code: public class User { public static void main(String args[]) { int array[] = new int[10]; int i = 1; try { System.out.println("try: " + i++); System.out.println(array[10]); System.out.println("try"); } catch (Exception e) { System.out.pri...

What is the PHP equivalent to Python's Try: ... Except:...

I am a strong Python programmer, but not quite there when it comes to PHP. I need to try something, and if that doesn't work out, do something else. This is what it would look like in Python: try: print "stuf" except: print "something else" What would this be in PHP? ...

Objective-C catch specific type of exception

Hi, I (as some of you know from my other questions :)) am building a cocoa-touch static library, and I have the code [NSException raise:@"This is the name of my exception" format:@"This is my format", nil] scattered throughout my project as a shortcut to subclassing NSException. This is coming back to bite me, as that I need to catch ONL...

Is it possible to patch a memory leak using a try-catch statement?

if(pCoeff.size()>thisCoeff.size()){ difference=pCoeff.size()-thisCoeff.size(); for(int i=thisCoeff.size(); i<thisCoeff.size()+difference;i++){ thisCoeff.add(i, new Double(0.0)); //this line throws errors } } I've isolated this portion of my program as being the cause of memory leak, is it...

C++ catch with multiple parameters

First I found in cplusplus.com the following quote: The catch format is similar to a regular function that always has at least one parameter. But I tried this: try { int kk3,k4; kk3=3; k4=2; throw (kk3,"hello"); } catch (int param) { cout << "int exception"<<param<<endl; } catch (int param,string s) { ...

TRY CATCH in SQL Server

I am using SQL Server 2008. I have tried to execute the following: BEGIN TRY SELECT 1/0; END TRY BEGIN CATCH PRINT 'ERROR' END CATCH; But I am getting the following error: >Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'TRY'. Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'END'. Can ...

Exception propagation through nested loops/calls

I'm having trouble understanding how exceptions should propagate. My code (quite similar to the generic code below) executes otherCode() and fails to continue outer when doSomething() throws the exception. I need to loop over parsing a bunch of files, some of which may be formated incorrectly (causing an exception), and then loop over ...

How to use try catch in NSIS

hi im getting a weird error on few machines in my nsis installer while installing. Its is giving "Invalid win32 file handle" while installing fonts using fontreg.nsh i've tried google but didnt got an answer to this issue. now im thinking to suppress this message, so is there any way to suppress the message or if possible suggest me sol...

.Net: Try...Catch paranoia - where does it end?

I think I have something like "programmer's OCD". I like my code to be esthetical and clean, and I want it to be "perfect" (as in handling all possible situations correctly and pretty). Often I find myself spending a lot of time just going over the same areas again and again to see where I can optimize and where I can fool-proof. So whe...