Questions tagged [catch-block]

The `catch-block` in a program is used to handle an `exception` thrown by a block of code.

144 questions
3
votes
0 answers

Why is throw and catch hardly ever used in Ruby?

I have recently gotten into a discussion over raise vs. throw. There is another SO thread discussing this, and the pundits summarized the situation as this: Throw and raise are, to a great degree, interchangeable Advantage of throw is that you can…
Boris Stitnicky
  • 12,444
  • 5
  • 57
  • 74
2
votes
1 answer

MVC RedirectToAction in a catch block

I´m trying to redirect to an action from one controller to another if something in a try-block goes wrong. What I want to achieve is a general way of presenting a view to the user if something goes wrong in different controllers by directing all…
Ebbe
  • 43
  • 6
2
votes
1 answer

get variable in catch clause

Hello I need to write function than will send and receive messages over tcp and auto reconnect if connection is broken. Messages is taken from STM Channel f ch a b = h <- connectTo a b forever $ do c <- atomically $ readTChan ch …
qnikst
  • 302
  • 1
  • 9
2
votes
2 answers

Capture stdout within a TCL catch command

In my main tcl script, I am calling a tcl proc wrapped in a catch command. This proc in-turn calls 10 more procs. When there is an error in execution in any of those 10 procs, TCL still continues execution of my main script as expected and I am just…
user9900698
2
votes
1 answer

Catch is not handling rejection of promise

so, my problem is the following. I'm returning a promise which resolves when there are no problems while storing some data, but if (1.) The directory where I want to to save the file doesn't exists or (2.) In that folder already exists a file with…
Nicolas4677
  • 43
  • 1
  • 1
  • 5
2
votes
1 answer

clang format catch with empty statement on single line

I am wondering if it is possible to get clang format to have the following formatting for exception handling. // Scenario 1: Catch and ignore exception try { DoWork(); } catch (const SomeException&) {} // Scenario 2: Handle exception try { …
2
votes
0 answers

Why is the wrong catch exception type executed?

I initialize my function with two commands. First, I load a configuration file with Get-Content and secondly, I import a module (Import-Module). try { Get-Content -Raw -Path Wrong-Path -ErrorAction Stop | ConvertFrom-Json Import-Module…
Alex_P
  • 2,580
  • 3
  • 22
  • 37
2
votes
1 answer

asynchronous function in promise throws error and doesn't reject

If there is a promise with an asynchronous function in it and if in the asynchronous function an error happens the promise doesn't catch but throws an error and crashes the application, which I don't understand. Obviously I would like to handle the…
2
votes
2 answers

What is the part after "catch" called?

What do we call the code highlighted in yellow? in code it would be: try{ ... } catch (Exception $e) { // the part within the brakets ... } I was thinking "catch expression" maybe, but I don't think I have ever read that anywhere.
AndreKR
  • 32,613
  • 18
  • 106
  • 168
2
votes
2 answers

Graceful shutdown of an amqp (and/or) http daemon, (and about global variables)

I wrote an API daemon. It hardly processes requests in the loop (inside processing it can call other services by http and amqp, overload sql database etc). I want to find the best way to make a graceful shutdown for it. So when it receives sigterm…
Dimitri
  • 623
  • 7
  • 14
2
votes
1 answer

Handling response errors/http status through fetch promises

This is kind of a two part question, the first being specific to my personal circumstance and the second being an overall understanding of how things function. I am performing a password reset for my application. The email gets sent along with a jwt…
Nappstir
  • 995
  • 2
  • 20
  • 38
2
votes
2 answers

Undefined method in multiple-exception-catch

I have two classes inheriting from java.lang.Exception. They both have a method with the same signature void a(){...}. They both can be thrown in a code block. If I do: catch (SubException1 | SubException2 e) { e.a(); } Then it…
pHneutre
  • 1,091
  • 3
  • 12
  • 29
2
votes
2 answers

expressJS promise and error handling

I have a route that first need to query the database, then with the results, query another web service, then with that result render the page. I have that flow worked out and am trying to figure out the error handling. Given that i talk to multiple…
otusweb
  • 1,638
  • 1
  • 19
  • 30
2
votes
1 answer

Java method with Generic argument called from result of catch block

I've run into an unexpected issue involving Exception catching and Java generics in signatures. Without further ado, the code in question (explanation follows): public class StackOverflowTest { private static class WrapperBuilder { …
scubbo
  • 4,969
  • 7
  • 40
  • 71
2
votes
1 answer

Code is only executing in the debugger - MS Visual C#

I'm using Microsoft Visual C# 2008 Express Edition. (And I apologize - this is more of a MS Vis C# usability question than a strict programming question...) I wrote a little program. when I run it in MS VC# with the debugger, all is well. When I…
adeena
  • 4,027
  • 15
  • 40
  • 52
1 2
3
9 10