The `catch-block` in a program is used to handle an `exception` thrown by a block of code.
Questions tagged [catch-block]
144 questions
0
votes
1 answer
Catch block in Java code gets executed even when the try block satisfies the mentioned condition?
I am new to Java and I tried to use exceptions in my Java code to give the user an alert if in case he/she types a negative number or a non-numerical value in the text field. But still, when I enter a single-digit positive number, the catch blocks…
0
votes
0 answers
UnhandledPromiseRejectionWarning: Unhandled promise rejection. Please help this non technical background person
I have node and npm, and I don't have an idea of how to fix this problem.
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a…

ejung2017
- 1
- 2
0
votes
1 answer
Rejected Promise breaks loop despite catch
I am creating a loop to create/update users using functions with built-in promises:
for (const user of usersjson.users) {
let getuser = getUser(url, okapikey, user[fieldMap.externalSystemId],
'externalSystemId'); //Check if user exists on the…

Nimrod Yanai
- 777
- 2
- 8
- 30
0
votes
1 answer
check if a class is defined in TCL OO, not using catch
I have a code, and I want to make sure that a class definion is indeed loaded.
Lets say that the class name is foo. I can do the following:
if { [ catch { foo new } ] } { source "path_to_code" }
Is there a way to do it without catch?

user1134991
- 3,003
- 2
- 25
- 35
0
votes
1 answer
Compile error for method reference in multiple exception handling
There is an interesting situation I have encountered. I have 2 exception classes MyException1 and MyException2. During multiple catch(MyException1 | MyException2 ex) SonarLint suggests using method reference (ex::getExitCode) instead of the lambda…

nikli
- 2,281
- 2
- 24
- 38
0
votes
2 answers
Promise data and exception handling
I am confused with the use of promise, specifically of its way of data manipulation (passing values from block to block) and exception handling (bubbling up the error). I am trying to learn a right way to use promise and to handle error, something…

mrchoc0
- 67
- 5
0
votes
0 answers
Spring Boot Controller Catch Block call from Junit
I have a controller class with a POST method with @RestController annotation
@RequestMapping(value="/test", method = RequestMethod.POST, produces ="application/json")
public Response updateDetails(@RequestBOdy Request request) throws…

Neela
- 107
- 2
- 10
0
votes
1 answer
Catch nobody for target patch
I want to check if target patches fulfil a condition. If a patch is found that fulfils the condition,
then the turtles should move there. If 'nobody' fulfils this condition, then an error message should be printed.
The condition is that a patch…

Hannah H.
- 266
- 3
- 14
0
votes
2 answers
Java RuntimeException catching multiple catch blocks
I have the following code
`
package com.test.Custom;
public class StreamError
{
public static void main(String[] args)
{
try
{
String str = "Hello";
if (!str.equals("Hello"))
{
…

Sugata Bagchi
- 123
- 11
0
votes
1 answer
Axios does not run - React JS
I am using axios to make a POST request with React JS, specifically a POST request to the Sendinblue API, found here. I have tried multiple variations using axios however I have not had any luck with successfully completing the POST request.
The…

tennis25
- 99
- 1
- 2
- 12
0
votes
1 answer
How to handle an async function called by an event?
Let's say I have async function named 'Main' that gets called during page load like this:
window.addEventListener('load', Main);
Since Main is an async function, I'd like to catch errors from its promise chain by appending .catch((e)=>{…

Lonnie Best
- 9,936
- 10
- 57
- 97
0
votes
3 answers
How to check the types of Exceptions thrown in a catch block?
I have something like this:
catch (Exception ex)
{
if (ex is "Exception Type")
{
}
else if (ex is SqlException)
{
}
else if
{
...
...
...
}
Is this right in C# and what…

LopDev
- 823
- 10
- 26
0
votes
2 answers
What is passed to the function in a Promise .catch block?
What's the general difference between these two styles of handling .catch blocks in Promises:
...
.catch(e => myMethod(e))
...
.catch(myMethod)
What does a Promise's .catch pass to the received method?
e.g. Can there be additional arguments?

janniks
- 2,942
- 4
- 23
- 36
0
votes
4 answers
Don't understand working of anymodel.findOne.then().catch()
I tried this code to login in my API
user.post("/login", (req, res) => {
let email = req.body.email;
let password = req.body.password;
userModel
.findOne({ $and: [{ email: email }, { password: password }] })
…

Jifri Valanchery
- 189
- 5
- 15
0
votes
1 answer
Exception or error handling in Protractor Jasmine
I have written a test case which contains multiple scope. Now, one of the test cases might be failed if text is not correct or wrong value or for waiting time. Normally it shows fail if those situation occurs. But I want to handle those errors so…

ktina51
- 25
- 1
- 8