Questions tagged [try-catch]

try-catch is a syntactic construct for catching exceptions raised by a code section

The try-catch construct for exception handling is used by a wide group of languages, like C#, C++, Matlab, Python, Java, and JavaScript. An example of this construct is shown below.

try
{
    Some code
}
catch(exception e)
{
    Handle exception
}

References:

8733 questions
3
votes
2 answers

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…
Apurva Saxena
  • 448
  • 1
  • 5
  • 13
3
votes
2 answers

Is it possible to catch a segfault with try/catch?

I did this test to see what happened: try { int *x = 0; *x = 1234; } catch(...) { cout << "OK"; } But it throws a segfault, why does it not catch the segfault?
cheroky
  • 755
  • 1
  • 8
  • 16
3
votes
3 answers

Is it possible to combine catches?

I'm trying to do this: catch LocksmithError.Duplicate, LocksmithError.Allocate {...} But I get an error at , saying : Expected '{' after 'catch' pattern Does this mean you can't combine cases like case expression2, expression3 :? Any reason…
mfaani
  • 33,269
  • 19
  • 164
  • 293
3
votes
1 answer

What happens when both catch block and finally block throw exception in Java?

Consider this question I was asked in an interview public class Test_finally { private static int run(int input) { int result = 0; try { result = 3 / input; } catch (Exception e) { …
user18424
  • 401
  • 1
  • 3
  • 8
3
votes
2 answers

try catch for performance c#

My knowledge with try catch is limited. But i wonder if it can be used to gain performance. Example, i am creating this voxel engine where a function is like this: Block GetBlockInChunk(Vector Position){ if(InBound(Position)){ return…
filipot
  • 176
  • 2
  • 10
3
votes
1 answer

Try and catch alternative

Is there an alternative to Try and Catch in AutoIt? I wonder if there is something similar.
jxtz
  • 51
  • 8
3
votes
1 answer

remove last method from stacktrace before throwing exception

I have a utility method for timing and logging various queries all over the project. The problem is, when looking at crashlytics now all unrelated crashes are joined together into one crash-instance. Can I catch all exceptions on the utility method,…
marmor
  • 27,641
  • 11
  • 107
  • 150
3
votes
1 answer

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…
Vibeeshan Mahadeva
  • 7,147
  • 8
  • 52
  • 102
3
votes
6 answers

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

I have the following code, but the alert box is not displaying. try { do something.. } catch(Exception ex) { Response.Write(""); } If I use this code, the alert box appears. try { do some…
Sheetal Inani
  • 128
  • 3
  • 5
  • 16
3
votes
2 answers

NodeJS - Why current domain is undefined in Promise?

I create domain and run it. Now while domain is entered process.domain points to current active domain. But then I run Promise and get something strange. 'use strict'; var domainCreate = require('domain').create; var domain =…
happy_marmoset
  • 2,137
  • 3
  • 20
  • 25
3
votes
3 answers

Continue code execution after an error and deal with them later in PHP?

I'm coding a simple php code for sending e-mails from a MySQL table with a mailing list; I'm doing the best I can to prevent errors from happening, to validate fields and do everything I can to prevent errors from happening. I'm going to use a…
Miguel Vieira
  • 144
  • 3
  • 17
3
votes
1 answer

return statement inside try catch and if else clause

The problem is that something strange is going on inside my code; Let's go to my example (i cleaned it a bit): public int foo() throws IOException { if(redirect_url.indexOf("statement_1") != -1){ if(check() == true){ …
Ascelhem
  • 413
  • 3
  • 21
3
votes
3 answers

Interrupting long running method pattern

I am currently using this somewhat tedious pattern to generate error message for user running some long operation: string _problem; void SomeLongRunningMethod() { try { _problem = "Method1 had problem"; Method1(); …
Sinatr
  • 20,892
  • 15
  • 90
  • 319
3
votes
1 answer

Call for asynchronous method in try-catch-finally block

I want to understand the following, suppose I have following block of code: try{ // do something asynchronousMethodCallThatWritesFileOutputStreamToSocket(fileOutputStream); }catch (SomeException e){ //handle exception }finally{ …
Evgeniy Mishustin
  • 3,343
  • 3
  • 42
  • 81
3
votes
2 answers

Yii2 - fatal error , try-catch not working

i want working with SoapClient in yii2 project. but i need manage error with try-catch. but that not work ! yii2 code example : class SiteController extends Controller { public function actionIndex() { try{ new…
Think Big
  • 1,021
  • 14
  • 24