The `catch-block` in a program is used to handle an `exception` thrown by a block of code.
Questions tagged [catch-block]
144 questions
71
votes
5 answers
Promise reject() causes "Uncaught (in promise)" warning
Once a promise reject() callback is called, a warning message "Uncaught (in promise)" appears in the Chrome console. Yet I have a catch handler in place. I can't wrap my head around the reason behind it, nor how to get rid of it.
var p = new…

Yevgeny Kozlov
- 1,151
- 1
- 8
- 11
61
votes
8 answers
Flutter and Dart try catch—catch does not fire
Given the shortcode example below:
...
print("1 parsing stuff");
List subjectjson;
try {
subjectjson = json.decode(response.body);
} on Exception catch (_) {
print("throwing new error");
throw…

John Gorter
- 2,162
- 2
- 17
- 25
24
votes
2 answers
Is "ANR" an exception or an error or what?
Is the ANR an exception, an error or what? Can we actually catch it in a try{} catch(){} structure?

lee lias
- 251
- 1
- 2
- 3
16
votes
3 answers
Swift Catch Pattern that binds the error to a variable
Using Swift 4.2 and XCode 10
In Swift 4.2, DecodingError is an enumeration. There are (currently) four different cases. I can catch each case separately, and bind variables that I can use to log the error as in the following code ...
do {
let…

escapedcanadian
- 283
- 5
- 10
15
votes
7 answers
Why brackets are necessary in catch block in java?
In java if we have to execute only one statement after if or for the brackets are not necessary. We can write:
if(condition)
executeSingleStatement();
or
for(init;condition;incr)
executeSingleStatement();
But in the case of catch block why we…

Harry Joy
- 58,650
- 30
- 162
- 207
15
votes
8 answers
Under C# how much of a performance hit is a try, throw and catch block
First of all, a disclaimer:
I have experience in other languages, but am still learning the subtleties of C#
On to the problem... I am looking at some code, which uses the try/catch blocks in a way that concerns me. When a parsing routine is…

Noah
- 15,080
- 13
- 104
- 148
13
votes
1 answer
Promise reject Possibly unhandled Error:
I have a function that does some operation using an array.
I would like to reject it when the array is empty.
As an example
myArrayFunction(){
return new Promise(function (resolve, reject) {
var a = new Array();
…

Juan
- 806
- 1
- 8
- 15
12
votes
5 answers
Is there a situation when it's appropriate to use empty catch block?
Possible Duplicates:
Why are empty catch blocks a bad idea?
Is there any valid reason to ever ignore a caught exception
Do you know any situations when an empty catch block is not the absolute evil?
try
{
...
// What and When?
…

bniwredyc
- 8,649
- 1
- 39
- 52
10
votes
6 answers
.net Exception catch block
What's the difference between the following catch blocks?
try
{
...
}
catch
{
...
}
and
try
{
...
}
catch(Exception)
{
...
}
I realize, in either case, the exception instance is not available but is there anything that I can do…

Bala R
- 107,317
- 23
- 199
- 210
9
votes
5 answers
Can we get LineNumber and ColumnNumber in try block at which exception occured
I have the below code with which i am able to print the fullclassname,classname,methodname, at which error occured.
Also, I am able to print Line-Number but the Line-Number printed is the line at which the variable "LineNumber" is initialized.
How…

Akki
- 1,221
- 3
- 14
- 33
9
votes
1 answer
Catch a exception with interface.
I have a question about the exception handling in PHP.
I have a lot of exception those means the same: Couldn't found something. All those exception implements the interface (not class) NotFoundException.
So to my question: It's possible to check if…

Matt3o12
- 4,192
- 6
- 32
- 47
8
votes
2 answers
Toast does not display when used in catch block
I noticed that a toast isn't displayed when it's used inside a catch block.
Does anyone know how to show toasts when catching exceptions? An Example:
try {
// try to open a file
} catch (FileNotFoundException e) {
Toast.makeText(this,…

cody
- 6,389
- 15
- 52
- 77
7
votes
6 answers
Detect when running inside a catch block
How do I detect when the currently-executing code is being called from within a catch block?
void SomeFunction()
{
// how do I detect whether I am being called from within a catch block?
}
EDIT:
For those asking, I wanted to implement a class…

bboyle1234
- 4,859
- 2
- 24
- 29
6
votes
10 answers
Why do try blocks need a catch
I have this code :
try
{
result.FirstName = nodes[myIdx]
.Attributes["ows_FirstName"].Value;
}
catch { }
Now I don't know prior to invoking this call if the attribute I am looking for exists (Good ol sharepoint).
As a result the only…

Maxim Gershkovich
- 45,951
- 44
- 147
- 243
6
votes
3 answers
C# catch(DataException) - no variable defined
static void Main(string[] args)
{
try
{
Console.WriteLine("No Error");
}
catch (DataException) /*why no compilation error in this line?*/
{
Console.WriteLine("Error....");
}
Console.ReadKey();
}
The code…

Manoj Agarwal
- 65
- 6