Most voted "try-catch" questions
Try-catch is a syntactic construct used in programming languages for handling exceptions, which can occur in a section or section of the program.
Learn more…71 questions
Sort by count of
-
46
votes2
answers11298
viewsHow does Try-with-Resources work?
In Java 7, the concept of Try-with-Resources was added in the language. What is the Try-with-Resources? How does it work? What does it serve? How is it used? What problem does it aim to solve?…
java exception try-catch try-finally try-with-resourcesasked 7 years, 11 months ago Victor Stafusa 63,338 -
27
votes5
answers31170
viewsWhat are Try/Catch Blocks for and when should they be used?
I’ve been looking for some explanations on the subject, but I couldn’t find one that was simple and straightforward. My question is : What Try/Catch Blocks are for and when they should be used?…
-
17
votes2
answers4913
viewsHow to check if a file is in use without launching C#exception
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 go to process them. How can I check if the file is in use?…
-
14
votes4
answers1204
viewsSpecific use of Try-catch
I am studying Hibernate and with it came some doubts that have come to me before but I did not question in depth. public void salvar(Usuario usuario){ Session sessao = null; Transaction transacao =…
-
13
votes2
answers869
viewsWhat is Finally for in PHP 5.5?
PHP 5.5 implemented a feature (which I’ve heard exists in other languages) called finally, in the handling of exceptions (together with the try/catch) We have the following example:…
-
10
votes2
answers229
viewsCan try catch be replaced by using?
I always used the blocks try, catch and finally when programming in Java, and when I switched to C# I noticed that some codes exchange the try/catch for using. Example: using (FileStream fs = new…
-
9
votes1
answer3553
viewsHow to use a Try catch inside another?
I need to write data into a database, and if it succeeds, then I will generate a .pdf with PHP. Even if I put one try catch in a part of the code and it gives the exception, still the rest of the…
-
9
votes5
answers819
viewsIs the rest of the code inside Try executed after finding Exception?
The rest of the existing code within a try is executed after finding a exception or jumps right into the code inside the catch(Exception e) try{ x = 10; //alguns erro de try catch x = 20; } catch…
-
9
votes4
answers785
viewsShould I use a "Try-catch" to identify if a password is wrong?
On the screen of login, carry out the verification in the bank by means of a select, and I’m using the catch to capture this exception. It is correct to use the catch for that guy? if (Usuario !=…
-
8
votes1
answer355
viewsCentralize (use only one) a Try-catch for every WPF application
Is there any way to centralize a try-catch for every application in a WPF application with C#? I created a window to use as MessageBox customized. When there is an error in any system registration…
-
8
votes1
answer322
viewsHow to turn E_PARSE errors into Exception in PHP?
My question is this:: PHP has a great feature that lets you convert errors that can occur in an application into Exceptions. This can be done through class ErrorException Example:…
-
8
votes1
answer1205
viewsDo I need to use Try/catch throughout a process chain?
Supposing I have a call in my layer controller for a method in the business layer that leads to another method in the data access layer. Should I use the try/catch in all of them, only in any or…
-
7
votes3
answers546
viewsRun program inside Try/Catch
Working with Visual Studio, when an error occurs while the program is running the program hangs and you can’t see where the program crashed and only appeared that error screen. To catch where these…
-
7
votes4
answers342
viewsWhat is the function of the " | " operator within the catch?
I read that || (OR) is for boolean operations and | (Bitwise Operation) for bit operations. What is your function within a catch with multiple exceptions, then? I mean, I know it eliminates…
-
7
votes5
answers2024
views -
6
votes1
answer1796
viewsExceptions in Java
I am studying about exceptions in Java and would like to understand better. When declaring an object, if the programmer predicts that a failure may occur in the execution of the method, he will…
-
6
votes1
answer1441
viewsExecution flow of a Try/catch/Finally block
How the execution flow works in a block try/catch/finally in the example below? public class ExceptionTest { public static void makeException() throws ExceptionAlpha, ExceptionBeta, ExceptionGamma {…
-
5
votes2
answers3052
viewsTry and Catch continue running (after Exception)?
How I put a block try and catch p/ continue the loop for, even if it does arrayindexofbounds and among other Exception? I put and it runs but the output of "m" does not print anything after! for…
-
5
votes2
answers203
viewsWhen to use "Try catch" in layered application?
Let’s say I have my layers Controller Business Repository so it is necessary to create this block in the 3 layers or create only in the controller? If I do this she ensures that every code that is…
-
5
votes2
answers379
viewsHandle 404 error without using Try/catch
I have the following code snippet that makes an HTTP request, only that sometimes the URL does not work, then will be launched an exception by framework. HttpWebRequest request =…
-
5
votes1
answer91
viewsIs it possible to make a mistake that triggers others?
Follow an example: public class Teste { public static void main(String[] args) { func1(); } public static void func1() { try { func2(); } catch (Exception e) { System.err.println("Error 1\n"); } }…
-
5
votes1
answer557
viewsIs it recommended to manipulate rules with "Try-catch"?
We can manipulate errors in various ways, but the one that will use less code and time of the programmer is the try, present in almost all object-oriented languages. But, when should be used try,…
-
5
votes3
answers203
viewsShould I always use Try catch to fix mistakes?
Sometimes when I know something may fail in my system I do a validation using if, equal is below: lista = [1,2,3] #um número que esteja entre os indices da lista numero = int(input(f'Digite um…
-
4
votes1
answer66
viewsWhy can’t we use Await inside a Catch, Finally and Synclock in VB?
Why can’t we use the operator Await within the statements Catch, Finally and Synclock in VB? The C# 6.0 has support to use the Await within the Catch/Finally.…
.net vb.net characteristic-language try-catch asynchronousasked 7 years, 11 months ago vinibrsl 19,711 -
4
votes2
answers790
viewsWhat are Try/Catch blocks?
I would like to know what the blocks are try...catch. I would like more information in Portuguese, because in English I didn’t understand much, only that it would be a kind of if...else. What are…
-
4
votes2
answers767
viewsHow to treat exception that cannot delete as it is a Foreign key
I am not able to treat an exception that happens when I delete an address that is being used in another table. I’m using the codeigniter my code is: public function…
-
3
votes1
answer140
viewsHow to use Try/Catch to read files
I have a method called readFileCredentials which aims to open a file and return the data that was inside that file, follows the code of that method: readFileCredentials = function(file, cb){ var…
-
3
votes1
answer143
viewsHow to not include Finally and still close IO Streams, Connections, Statements, and other Resources?
We know the need to close resources (files, connections, also called Resources) consumed in Java, such as OutputStream and InputStream. When we don’t close them, we create performance problems and…
-
2
votes1
answer73
viewsWhich errors trigger the catch?
In a test similar to this, I was in doubt of what mistakes generate the Exception. Researching I only found explanations of the use of try, catch, and some references that this would depend on the…
-
2
votes1
answer77
viewsCode snippet in Try
I was making corrections in a class and I came across the following code, I didn’t know it was possible and I never stopped to think, but why is this valid? I mean first line of the Try. For me…
-
2
votes3
answers511
viewsWhat is the most recommended "Try" or "if"
{ public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { double SalarioBase = 0, Descontos = 0, Vantagens = 0; try { SalarioBase =…
-
2
votes2
answers1315
viewsHow to use Try, catch, Finally and Exception in php
I’m with source where I need now adapt it to use the try, catch, finally and exception and I’m not getting it, this source already has some try´s with catch(PDOException $erro) where I do some…
-
2
votes2
answers645
viewsWhere should I place the Try/Catch blocks using MVC?
I am making a web application in java and I have some doubts regarding the block Try catch, I am using the standard MVC and I have the following codes: Controller: try { String pesquisa = "%" +…
-
2
votes1
answer259
viewsHow to handle errors during web scraping?
Hello, everyone. During the Web Scraping process, I started to come across some errors that occur during the request process. Currently, I have identified 4 types of frequent errors: Error in…
-
2
votes1
answer452
viewsPHP error - Try_catch
Parse error: syntax error, Unexpected 'catch' (T_CATCH), expecting end of file in C: xampp htdocs validar_cad_usuario face.php on line 65 My Project is here if anyone can help, I thank you! try { //…
-
2
votes0
answers61
viewsTake the value of Try and fix to Return
I would like to redeem the result value that is inside Try, the code is correct directly in Activity, but when I put in asyncTask I cannot set it in the Return result;. Follows the code AsyncTask:…
-
2
votes1
answer65
viewsHow to implement java exception handling within a swtich-case?
I have to do a treatment for possible exceptions within a calculator, one of them would be the division by 0, in the case "Arithmeticexception", but I’m not able to make it work, even after…
-
2
votes1
answer59
viewsError handling is not occurring
In the code below I treated the error only that after treating it still appears the quantity name (I sent the photo below to facilitate understanding). How do I make him not show the quantity name?…
-
2
votes1
answer57
viewsJava 8 SE: Finally block of a method is running before entering the method
On page 359 of the Book: Java - How to Program - 10th Edition. Deitel explains the treatment of Java exceptions. It exemplifies the question with the following code: public class UsingExceptions {…
-
1
votes2
answers841
viewsWhat exceptions should I capture in a Try-catch?
I have some doubt in try catch in relation to which types of exceptions put. In this example either would be the best option? try { String folerPath = Environment.getExternalStorageDirectory() +…
-
1
votes2
answers68
viewsIs it necessary to place the element type inside the Try?
When optimizing my JDBC code I started using a condition within Try. /** Função PreparedStatement stmt */ public PreparedStatement stmt; /** Funçãoo ResultSet rs */ public ResultSet rs; /** Método…
-
1
votes1
answer138
viewsJavascript Runtime Exception
I’m trying to make a dynamic file call where I have one input that receives a name and is loaded a file with this name in the <source> in js, when the person enters a file name that does not…
-
1
votes0
answers46
viewsUsing Try-with-Resources in Java code
I have a following problem, I am unable to pass a code that I currently have and that is wrong, it works but does not close the connection to bank and gives too much error, and I wanted to use it…
-
1
votes2
answers74
viewsSkip file when entering an Exception
Good afternoon Below is a method I use to read certain files from a folder. The problem is as follows. If the folder has 50 files (or 60, or 70, or 80 ...) and the method is reading a "faulty" file…
-
1
votes1
answer480
viewsGet error message in Httpclient Post
I have a WCF Service on a server whose service is also configured as Webinvoke: [WebInvoke( Method = "POST", UriTemplate = "/work", BodyStyle = WebMessageBodyStyle.WrappedResponse, ResponseFormat =…
-
1
votes0
answers252
viewsIf or Try/Catch?
here at work I came across a code that deals error in an if instead of Try/Catch. The programmer justifies that the catch interrupts the code, but I believe that a Finally ensures the execution. Can…
-
1
votes2
answers1138
viewsHow to use Try and catch with PHP?
I have a question about how to apply the try and catch in a method. public function cadastrarUsuarios(parametros){ mysqli_query($this->conexao,"INSERT...."); // Aqui que vem a dúvida try{…
-
1
votes1
answer70
viewsTry-catch in loop causing error
I have the following code, which tries to click a button after 60 seconds, and if it has not pressed, try again after 60 seconds. while(true) { var timeout = setTimeout(function() { try{…
-
1
votes1
answer104
viewsTry-except, Indexerror, Alternatives to fix the error
I’ve got a college job to do, in a way I finished it, but with a few tricks I wanted to set up and make the code less confusing and so on. Operation of the programme: Basically it creates a 600x400…
-
1
votes1
answer68
viewsWhat is the risk of an error on an already loaded page?
I have an application where large data in AJAX requests are made, this generates a certain delay to place the data on the page. I need to render an image where your path is a array. In my…