try-catch

Difference between try-finally and try-catch

What's the difference between try { fooBar(); } finally { barFoo(); } and try { fooBar(); } catch(Throwable throwable) { barFoo(throwable); // Does something with throwable, logs it, or handles it. } I like the second version better because it gives me access to the Throwable. Is there any logical difference or a pref...

Problem with continue in While Loop within Try/Catch in C# (2.0)

Update2 okay, i was able to get it to work, but i think there is a problem having two different datareaders whiles within another. after moving it out of the outer while in a method it works. The Exception from the 1st update was because i didn't closed the reader, so it opened too many tables an JET crashed on the 2048 open tables. So b...

Tell SQL Server the error is "handled" in try...catch

I'd like to indicate to SQL Server 2005, in my BEGIN CATCH...END CATCH block that the error is "handled"... That is, clear the error. Is that possible? Consider this: begin transaction begin try begin transaction select cast('X' as bit) commit transaction end try begin catch rollback transaction select...

Why doesn't Perl's Try::Tiny's try/catch give me the same results as eval?

Why doesn't the subroutine with try/catch give me the same results as the eval-version does? #!/usr/bin/env perl use warnings; use strict; use 5.012; use Try::Tiny; sub shell_command_1 { my $command = shift; my $timeout_alarm = shift; my @array; eval { local $SIG{ALRM} = sub { die "timeout '$command'\n" }; ...

Is there a way in VS2008 (c#) to see all the possible exception types that can originate from a method call or even for an entire try-catch block?

Is there a way in VS2008 IDE for c# to see all the possible exception types that can possibly originate from a method call or even for an entire try-catch block? I know that intellisense or the object browser tells me this method can throw these types of exceptions but is there another way than using the object browser everytime? Somet...

in C# try -catch , can't catch the exception

below code can't catch the exception. does catch can't catch the exception which occured in the function? try { Arche.Members.Feedback.FeedbackBiz_Tx a = new Arche.Members.Feedback.FeedbackBiz_Tx(); a.AddFreeSubscriptionMember( itemNo, buyerID, itemName, DateTime.Today,DateTime.Today); } catch(Exception ex...

Catching constraint violations in JPA 2.0.

Consider the following entity class, used with, for example, EclipseLink 2.0.2 - where the link attribute is not the primary key, but unique nontheless. @Entity public class Profile { @Id private Long id; @Column(unique = true) private String link; // Some more attributes and getter and setter methods } When I insert re...

Can't declare unused exception variable when using catch-all pattern

what is a best practice in cases such as this one: try { // do something } catch (SpecificException ex) { Response.Redirect("~/InformUserAboutAn/InternalException/"); } the warning i get is that ex is never used. however all i need here is to inform the user, so i don't have a need for it. do i just do: try { // do someth...

microsoft windows driver kit pure C try catch syntax ?

In the Windows Driver Kit (WDK) there are some driver code samples written in pure C, but sprinkled with some try-catch-finally constructs. Does someone know their semantics ? Thank you microsoft for your great tools and standards compliance. Code extract from some_file.c: try { ... if (!NT_SUCCESS( status )) { leave; /...

Catching an exception that is nested into another exception

Hi, I want to catch an exception, that is nested into another exception. I'm doing it currently this way: } catch (RemoteAccessException e) { if (e != null && e.getCause() != null && e.getCause().getCause() != null) { MyException etrp = (MyException) e.getCause().getCause(); ... } else { ...

Try catch finally blocks.. do i still need them when handling errors in the global.asax?

I am handling errors via my global.asax in this method: Dim CurrentException As Exception CurrentException = Server.GetLastError() Dim LogFilePath As String = Server.MapPath("~/Error/" & DateTime.Now.ToString("dd-MM-yy.HH.mm") & ".txt") Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(LogFilePath) sw.WriteLine(DateTime.Now....

Android - How to tell is someone has pressed a SPINNER but not changed the visible item in it.

I have a spinner, which mostly works. If a user selects one of the items in it, the 'onItemSelected' routine catches it just fine. But if a user clicks the same spinner, but does not change from the already visible item that it's currently displaying, the 'onItemSelected' routine just ignores it, and the logs show:- WARN/InputManagerSe...

SQL Try catch purpose unclear

Let's suppose I want to inform the application about what happened / returned the SQL server. Let's have this code block: BEGIN TRY -- Generate divide-by-zero error. SELECT 1/0; END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() as ErrorState, ...

[iPhone]how to catch signal "EXC_BAD_ACCESS" ?

Hello, i would like to log every crash of my application... so i've tried to catch all signals. But it seems not working for "EXC_BAD_ACCESS" Someone know... If is it possible to catch it ? And how ? ...

Assign final variable in a try block

Very short question: Is there a more elegant way to do this: Object tmp; try { tmp = somethingThatCanFail(); } catch (Fail f) { tmp = null; } final Object myObject = tmp; // now I have a final myObject, which can be used in anonymous classes ...

How to free memory in try-catch blocks?

Hi, I have a simple question hopefully - how does one free memory which was allocated in the try block when the exception occurs? Consider the following code: try { char *heap = new char [50]; //let exception occur here delete[] heap; } catch (...) { cout << "Error, leaving function now"; //delete[] heap; doesn't wo...

Should database insertions, updates and deletions be wrapped in try/catch?

I always use a try catch when i am dealing with database related operations for eg. try { DataContext.AddtoObjectname(obj); DataContext.SaveChanges(); } catch(Exception e) { throw new Exception("Problems adding object" + e); } But I read about try/catch affecting performance here - http://stackoverflow.com/questions/1308432/do-try...

in a try-block, how to do sth. if no exception occurs ? obj-c

in a standard try-catch-error-block, how can i advice the programm to do something only, if no error is thrown ? for example, if i want to configure a proxy for something ip-based, and if it all works, it should grey-out the button. ...

TSQL Create trigger with transaction and try catch block

Hi ! i have some questions about a transaction in the trigger, for which I haven't found an answer yet. CREATE TRIGGER A_AI ON A AFTER INSERT AS BEGIN TRY --is the try block 1 transaction ? or do I have to begin the transaction? --BEGIN TRAN: may I start the transaction like this? -- SOME DANGEROUS OPERATIONS ...

R warning message on recursive expression: If you fail, try, try again...

I want to create a function that will retry an expression if it fails. Here's my working version: retry <- function(.FUN, max.attempts=3, sleep.seconds=1) { x <- NULL if(max.attempts > 0) { f <- substitute(.FUN) x <- try(eval(f)) if(class(x) == "try-error") { Sys.sleep(sleep.seconds) return(suppressWarnings(...