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
5 answers
Compile/ Catch an exception
I am having a lot of trouble with this code. The code compiled and ran as it was suppose to before I tried to put in the code to catch an exception. Then I could no longer get it to compile. It is suppose to catch an exception and produce an error…

Diallo Dickerson
- 207
- 2
- 7
- 9
0
votes
2 answers
Why is the catch block not hit in the following Rx Code?
Just confused about why the flow doesn't reach catch block. I do understand that whenever an exception has occured OnError method will be called, but shouldn't an exception occur when ToObservable is called? It is only when processing the third…

Sandbox
- 7,910
- 11
- 53
- 67
0
votes
1 answer
'Await' cannot be used inside a 'Catch' statement, a 'Finally' statement, or a 'SyncLock' statement
I try to reproduce logic of C# program on my VB program, all going fine except one future, VB don't allow to reproduce this construction:
try
{
await nextButton[1].ClickAsync();
}
catch
{
await nextButton[0].ClickAsync();
}
Of course, I can…

Viacheslav Dev
- 21
- 6
0
votes
0 answers
Why am I catching a rejected Promise in a try/catch instead of the Error the Promise was rejected with?
Javascript in a webbrowser.
There is an async event handler. Inside this event handler a try/catch is used. Inside the try block an asynchoronous functions is called synchronously with await.
Inside the catch block the caught data should be…

Creech
- 258
- 2
- 12
0
votes
1 answer
JavaScript Try Catch report errors in console only after program exits
This piece of code is supposed to loop forever until the user enters the correct answer in a prompt. The right answers are "left" and "right". If the user enters any other text, then function promptDirection throw an error and execute catch block…

Jarkko Hietala
- 11
- 2
0
votes
1 answer
Is it wise to have if logic inside a python catch block?
Consider the following method that checks if a parameter contains a valid UUID string and generates a new one if it isn't and if the option is set:
def validate_uuid(val, generate):
try:
uuid.UUID(str(val))
return val
except…

mesllo
- 545
- 7
- 29
0
votes
1 answer
Selecting Catch Block (in visual studio) with Regular Expression Search
I want to select all catch blocks (in my C# code in visual studio) using regular express search but unable to create a regular expression that selects all catch blocks (including empty blocks and blocks with different exception handling)
I have…

Abdullah
- 11
- 1
0
votes
0 answers
Nodejs express - Return a value and assign it into a variable in catch block
So I'm getting a value from the database and I want to assign it into a variable but somehow it's returning undefined, but if I console log the value I'm trying to get it shows
first attempt I declared a value year
let year = 0
…

Phakamani Xulu
- 79
- 6
0
votes
1 answer
Uncaught (in promise); Thrown error in fetch() not being caught
I've already read tons of resources to try to help me on this. This gist did not solve it for me (https://github.com/github/fetch/issues/203#issuecomment-266034180). It also seemed like this (JavaScript Promises - reject vs. throw) would be my…

BVBAccelerate
- 172
- 1
- 5
- 17
0
votes
1 answer
How to cover try/catch block in angular unit testing
checkDefault(event) {
try {
this.defaultCard = event.checked;
this.cardInfo.forEach((s) => {
if (s.isDefault && event.checked) {
const dialog = this.dialogService.dialogMethod(this.message.isDefaultAlertCard,…

Naveen kumar
- 1
- 1
0
votes
1 answer
How to cancel the observable calls when exist an error in rxjs observable sequence that is requiring sequencial execution?
I have a sequial list of observables is requiring sequencial execution (these are in concat operator but I can remove in forkjoin), but when error is happening I need to stop the sequential results. How to abort the remaining observables when any…

Tabares
- 4,083
- 5
- 40
- 47
0
votes
0 answers
Type 'void | DiscordServer[]' is not assignable to type 'DiscordServer[]'
I'm getting this error while trying to call an async function. This is my code:
let result:DiscordServer[]
result = await Backendless.Data.of( backendlessDiscordServersTable! ).find( queryBuilder )
.catch( e =>…

Carlos de la Lama-Noriega
- 81
- 1
- 6
0
votes
2 answers
Swift 5: Error in success/failure block "'catch' block is unreachable because no errors are thrown in 'do' block"
I am writing a closure with error handling, but I am getting a warning "'catch' block is unreachable because no errors are thrown in 'do' block" in the catch line.
This is my code:
class Service {
func graphQL(body: [String:Any], onSuccess:…

akitainu22
- 95
- 1
- 8
0
votes
1 answer
How to differentiate the http error with other types of run time error in Axios react?
I am using the Axios in react app to send the HTTP request.
but how to differentiate for the runtime error or the HTTP error in the catch block.
axios.get(getCertUrl)
.then(async (response) => {
// operation might…

rahul Kushwaha
- 2,395
- 7
- 32
- 64
0
votes
1 answer
How to refactor this If/else statement in a try/catch block?
I was wondering if there is a better way to code this piece of code:
private void getLatitudeAndLongitudeFromZipcode() {
String zipcode = mSharedPreferences.getString("Zipcode", "");
try {
List address =…

Ely Jacobi
- 7
- 1