The `catch-block` in a program is used to handle an `exception` thrown by a block of code.
Questions tagged [catch-block]
144 questions
2
votes
2 answers
Using same catch block for multiple then methods
Given:
NodeJS v0.10.25
All Harmony features enabled
"use strict"
And the following code:
db.connect({
host: DB_HOST,
port: DB_PORT
}).then(function(dbConn) {
console.log('DBASE connected to ' + DB_HOST + ':' + DB_PORT);
…

Ryan Southwell
- 23
- 5
2
votes
2 answers
Unreachable code with multiple catch statements
Why does line 2 compile while line 3 does not?
spit() throws a HurtException that has already been caught on line 1, so any checked exception that comes afterwards should be unreachable. If I delete line 2, line 3 will remain reachable. Exceptions…

Helenesh
- 3,999
- 2
- 21
- 36
2
votes
1 answer
Powershell unexpected behavior of uncaught exception inside a catch block
The following powershell script produce a very unexcepted output:
try {
throw "some exception"
echo "check point"
}
catch
{
echo "catch"
throw "some other exception"
exit(-1)
}
echo "finish"
output:
catch
finish
I would except…

tsahi glik
- 21
- 2
2
votes
2 answers
Check if an argument is a dictionary or not in Tcl
I want have a proc which does something if its' argument is a Tcl 8.5 and above dictionary or not.
I could not find anything straightforward from Tcl dict command.
The code which I could get working is:
proc dict? {dicty} {
expr { [catch {…

user1134991
- 3,003
- 2
- 25
- 35
2
votes
1 answer
Throwing exception after modifying its Dictionary
The following is my code in C#:
catch(Exception ex)
{
ex.Data.Add("VarName", "object");
throw;
}
Question: doing above, am I going to lose the entry I am adding to Data dictionary? -->as in my opinion, I am rethrowing the exception caught in…

coder0h1t
- 443
- 5
- 9
1
vote
1 answer
Why does catch not properly invoke handler when using Maybe?
Consider the following Haskell code
try_lex_rgx :: String -> IO (Maybe [RgxToken])
try_lex_rgx rgx_str =
catch
(do
rgx_toks <- evaluate $ lex_rgx rgx_str
return $ Just rgx_toks)
(\(LexerErr err_msg remainder) ->…

Mark Mizzi
- 11
- 1
1
vote
1 answer
Dealing with errors in promises that are unanticipated and thus don't trigger reject()
In the following javascript code, why does the error (generated by the assignment to an non-existing object property inside the promise) not get caught by the .catch() on the promise, but does get caught by the window.onunhandledrejection function?…

Amorphia
- 130
- 6
1
vote
1 answer
Strange problem with return in catch block in Java
I've got a strange problem with a try/catch block I'm using. I've got this method, which just gets some data from a remote service and stores it.
public WFSGetCapabilitiesResponse wfsGetCapabilities(String url) {
WFSGetCapabilitiesResponse…

DeadPassive
- 877
- 3
- 8
- 22
1
vote
1 answer
how to fix UnhandledPromiseRejectionWarning
I am trying to fix my error but i don't know how. i have researched around looking for node UnhandledPromiseRejectionWarning but i haven't been able to fix it.
function getBandsInTown(artist) {
var artist = userInput;
var bandQueryURL =…

Aaron Lanier
- 11
- 3
1
vote
2 answers
Multiple methods with same try/catch logic
I have a C# program with multiple methods with different parameters and different return types, but most of them have a try/catch block with the same exception logic handling. There are multiple catch statement for all methods, but the logic inside…

Angela
- 477
- 1
- 10
- 20
1
vote
1 answer
React Native Possible Unhandled Promise Rejection (id: 0):
I'm trying the save picture from expo camera. After that i will send this picture to cloudinary. Therefore i need base64 properties. But i have a problem.
takePictureAndCreateAlbum = async () => {
const { uri } = await…

Ebru Gulec
- 653
- 2
- 7
- 16
1
vote
1 answer
Toast from (@remobile/react-native-toast) doesn't display
First, the problem occurs under ios simulator (all virtual devices).
Dependencies:
@remobile/react-native-toast": "^1.0.7"
"react-native": "0.56.0"...
Description of the problem:
I simulate an api error in an async method like that :
async…

Edd M
- 31
- 4
1
vote
1 answer
React, Immutable, fetch() - incorrect error handling leading to undefined state element?
I think I understand where the error is occurring but I am able to work out the correct handling flow for a Promise returned from fetch()
My Messages reducer module: -
import { fetchMessages } from '_helpers/api'
import { Map, fromJS } from…

U4EA
- 832
- 1
- 12
- 27
1
vote
1 answer
How would you catch the error
How would you catch the error in that case:
getStuff(): Observable {
return this.http.get(url)
.map((res: Response) => {
return res.json()
.map(item => {
return {
id: item.id
…

Sergino
- 10,128
- 30
- 98
- 159
1
vote
2 answers
Throwing and catching IOException
inputFileName = "2.txt";
outputFileName = "3.txt";
inputFile = new BufferedReader(new FileReader(inputFileName));
outputFile = new PrintWriter(new FileWriter(outputFileName));
String lineOfText = inputFile.readLine();
while…

MasterCard
- 13
- 1
- 5