Questions tagged [catch-block]

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

144 questions
1
vote
3 answers

Catch() not handling 404

I'm making a script to fetch some data from my api: const success = (response) => { console.log(response); }; const failed = (error) => { console.log(error); }; axios.$http.get('/somedata') .then((response) => { success(response.data); …
Jordy
  • 4,719
  • 11
  • 47
  • 81
1
vote
0 answers

angularjs style guide - How do i use this catcher implementation inside a controller or factory/service methods?

From the John Papa style guide for angularjs 1.x. I see the below implementation for an ecxeption catcher. however there is not an example of usage. Could someone provide some examples how to use this in controllers, factories or service…
blogs4t
  • 2,329
  • 5
  • 20
  • 33
1
vote
5 answers

Why throw at derived class catches by base?

For the code below, result is "EA Exception Finished", which means although we threw at derived class it caught by base class. Is it always? And if so, how can I make the derived class catches, thus "EB Exception Finished" appears? Also I can't…
RyanC
  • 189
  • 1
  • 9
1
vote
1 answer

powershell catch [System.Management.Automation.MethodException] error

in powershell, under certain condition , i do this : throw [System.Management.Automation.MethodException] later i have catch like this : catch [System.Management.Automation.MethodException] { catch { My code falls into the second (general) catch.…
petercli
  • 629
  • 1
  • 8
  • 27
1
vote
1 answer

Angular 2 private variables disappear

I have the following code which is a simple service that goes back to the server to fetch some data: import { Injectable } from '@angular/core'; import { Action } from '../shared'; import { Http, Response, Headers, RequestOptions } from…
Werner Swart
  • 371
  • 2
  • 4
  • 13
1
vote
3 answers

Catch multiple exceptions and throw a new list of exceptions

Look at the following code: public void editProduct(String articleNumber, ...) { product.setArticleNumber(articleNumber); product.setDescription(description); product.setLendable(lendable); product.setName(name); product.setPrice(price); …
Demian
  • 390
  • 2
  • 14
1
vote
0 answers

Xamarin Android (VS2013) not catching exceptions

I am working with the latest version of Xamarin Android in Visual Studio 2013. When I debug my code, the catch blocks are not catching any thrown exceptions. It was working, and then it just seemed to stop. I have no idea what happened. The…
1
vote
2 answers

Catch error and restart the if statement

I have a powershell script that adds a computer to a domain. Sometimes, when I run the script I get the following error and when I run it for the second time it works. How can I make the script to check if I get this error, and if so then to retry…
user01230
  • 563
  • 1
  • 6
  • 16
1
vote
1 answer

Tcl Script: Invalid command name return when executing proc body

In a Tcl script, I want to catch the return of a Tcl proc in order to execute some finalization actions. For example my code could be as follows: proc X10 { a } { return [expr $a * 10] } proc procF {} { set a 13 catch {[info body X10]}…
Devos
  • 142
  • 2
  • 11
1
vote
1 answer

How to avoid exception, and

I'm trying to render a page, but there is the possibility that some EL Expressions will generate some exceptions. So I tryed first of all, to sorround by block with a < c:if> in such the way that it shows the code only by checking the critical…
Sam
  • 313
  • 4
  • 21
1
vote
1 answer

Trouble using catch in simple tcl proc

I have the following proc which basically looks upp a couple of values in a dictonary and returns them as a list. proc GetAllow { PID Ply } { # read a dictonary from a file catch { append PlyAndDirXt $Ply "_xt" append PlyAndDirYt $Ply "_yt" set…
Lumpi
  • 2,697
  • 5
  • 38
  • 47
1
vote
2 answers

Invoke-Sqlcmd sometimes reports TSQL errors and sometimes it does not?

I'm confused: The following code produces an error: try { invoke-sqlcmd -ServerInstance 'localhost' -Database 'tempdb' -Query 'CREATE TABLE foo (bar TINYINT IDENTITY(1,1) DEFAULT 1);;' -Verbose -ErrorLevel 0 -AbortOnError -ErrorAction Stop…
eghetto
  • 263
  • 1
  • 3
  • 13
1
vote
3 answers

Statements within catch block is not executing

I wrote a piece of code to catch specific exception with help from this link. It is like: catch (SQLException sqle) { // TODO Auto-generated catch block String sqlMessage = sqle.getMessage(); String sqlState = sqle.getSQLState(); int vendorCode…
Mistu4u
  • 5,132
  • 15
  • 53
  • 91
1
vote
3 answers

Several "ChildException" catch blocks versius one "Exception" catch block

What's better between several ChildException catch blocks and one Exception catch block? By better, I mean in a good-practices way. To illustrate: public static void main(String[] args) { System.out.println(Main.isNonsense1(null)); // false <-…
sp00m
  • 47,968
  • 31
  • 142
  • 252
0
votes
1 answer

Catch ImageIO:

is it possible to catch the error "ImageIO: JPEGMaximum supported image dimension is 65500 pixels" I have wrote try,catch section for the corresponding method.However the catch block didn't catch the ImageIO exception!! The below code catch block…
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102