Questions tagged as 'try-catch'

4
answers

What are Try / Catch Blocks for and when should they be used?

I've been looking for some explanations on the subject, but I have not found any that are simple and straightforward. My question is: What are Try / Catch Blocks for when they should be used?     
asked by 15.04.2015 / 15:18
2
answers

How to check if a file is in use without throwing C #

I have an application that processes a file queue. I need to open the files for reading and writing. Sometimes the files are in use when I process them. How can I check if the file is in use? Today I deal more or less like this. I cr...
asked by 14.02.2014 / 18:08
4
answers

Specific use of try-catch

I'm studying Hibernate and with it came some doubts that have come to me before but did not question in depth. public void salvar(Usuario usuario){ Session sessao = null; Transaction transacao = null; try{ sessao = Hiberna...
asked by 15.01.2016 / 14:22
2
answers

What is the finally used in PHP 5.5?

PHP 5.5 has implemented a feature (which I've heard of in other languages) called finally , in handling exceptions (along with try/catch ) We have the following example: set_error_handler(function ($errno, $errstr, $errfile, $er...
asked by 26.01.2015 / 15:42
4
answers

Should I use a "try-catch" to identify if a password is wrong?

In the login screen, I check the bank with select , and I'm using catch to catch this exception. Is it correct to use catch for this type? if (Usuario != string.Empty && Password != string.Empty) {...
asked by 21.07.2016 / 16:04
1
answer

How to use a try catch within another?

I need to write data to a database, and if it succeeds, then I will generate a .pdf with PHP. Even though I put try catch in a part of the code and it gives exception , still the rest of the code will be executed. Would it...
asked by 03.10.2014 / 16:45
5
answers

The rest of the code inside the Try runs after encountering Exception?

The rest of the code within a try is executed after finding a exception or skips directly to the code within catch(Exception e) try{ x = 10; //alguns erro de try catch x = 20; } catch (Exception e) { x++; Message...
asked by 17.10.2016 / 13:00
1
answer

Do I need to use try / catch throughout a process chain?

Assuming I have a call on my controller layer for a method in the business layer that leads to another method in the data access layer. Should I use try/catch in all of them, just in some or depends? Below, as an example, I'm usin...
asked by 16.05.2016 / 17:06
1
answer

How to turn E_PARSE errors into Exception in PHP?

My question is: PHP has a great feature that allows you to convert errors that can occur in an application to Exceptions . This can be done through the class ErrorException Example: set_error_handler(function ($errno, $errst...
asked by 15.01.2015 / 18:15
5
answers

Return inside try ... catch does not work

I made this method: public int VerificaUltimaAnalise() { //Desenvolvimento WFExecutor vcmpExecutor = null; WFAnalise vcmpAnalise = null; Core vmpaCore = null; int vintCdTransa...
asked by 23.01.2015 / 14:03