Questions tagged [try-catch]

try-catch is a syntactic construct for catching exceptions raised by a code section

The try-catch construct for exception handling is used by a wide group of languages, like C#, C++, Matlab, Python, Java, and JavaScript. An example of this construct is shown below.

try
{
    Some code
}
catch(exception e)
{
    Handle exception
}

References:

8733 questions
3
votes
1 answer

Passing a address via intent to Google map activity:

I am working on an app that gets the address of an event the user selects. The address is a String and is passed from one activity to a Google Map activity. I know the string arrives in the map activity as I have used a Toast to display it. However,…
Pony1487
  • 123
  • 1
  • 6
3
votes
2 answers

Why is my function ending (using external library)

I need your help with some error handling. I'm using an external library but have no clue of what's happening with the error. Here's my code: //file name = playground.js var ccxt = require("ccxt"); ccxt.exchanges.map(r => { let…
Martin Carre
  • 1,157
  • 4
  • 20
  • 42
3
votes
2 answers

R tryCatch handling one kind of error

I wondering it is the way to check in tryCatch function kind of errors or warnings like in Java for example. try { driver.findElement(By.xpath(locator)).click(); result= true; } catch (Exception e) { …
3
votes
1 answer

Skip occasional error in loop

I am aware that the "skip error in for loop" has been answered multiple times (see How to skip an error in a loop or Skip Error and Continue Function in R). But all answers are complex and difficult to apply to a different situation for a novice. I…
Gabriel123
  • 426
  • 5
  • 11
3
votes
1 answer

tryCatch() or exists() in R pipe chain error handling

I am currently experiencing a hiccup where I am trying to create a table of values from some upstream calculations. Typically, I've been assuming that there would be at least one value of 1 each time these data frames are created; but I've…
deeboeh
  • 91
  • 8
3
votes
2 answers

C++ successful `try` branch

Let's consider some artificial C++ code: int i = 0; try { someAction(); } catch(SomeException &e) { i = -1; } i = 1; ... // code that uses i I want this code to assign -1 to i in case of someAction() throws exception and assign 1 in case if…
Nikolai Shalakin
  • 1,349
  • 2
  • 13
  • 25
3
votes
1 answer

Catch error in Component from async Vuex Action

I have an async action, like so: export const fetchTweets = async ({ commit, state }) => { const tweetFetchError = error => { // throw here? } try { const { oAuthAccessToken, oAuthAccessTokenSecret, user: { id } } = state const {…
benhowdle89
  • 36,900
  • 69
  • 202
  • 331
3
votes
0 answers

Catch block being bypassed on boost exception

Environment: Windows 10, Visual Studio 2015, x64, Unicode, boost 1.64 I'm having problems determining why a catch block is not being hit when a boost exception is purposely attempted. The point it to let boost tell me if a source string for a date…
BobC
  • 91
  • 3
3
votes
1 answer

Powershell try block not working on VSTS build

I'm running a command in Powershell through VSTS to affect Azure. The command works, but it gives an error after. The params and connection are working as evidenced by the fact that the group gets permission from the command. I figure a workaround…
user3364161
  • 365
  • 5
  • 21
3
votes
2 answers

PowerShell Try/Catch with If Statements

Problem/Details I am working in PowerShell and trying to figure out how custom Try Catch statements work. My current major issue involves mixing Try/Catch and If statements. So the idea of what I am trying to achieve is something like this: try { …
Brandon
  • 731
  • 2
  • 12
  • 29
3
votes
1 answer

Handling segmented error: NA breakpoint(s) at the boundary

I have a function that tries to apply a piece-wise regression model to my data. In some cases, the data has a generous amount of missing values and I don't have a good estimator of where the knots will be. I decided to bypass the piece-wise and go…
Matias Andina
  • 4,029
  • 4
  • 26
  • 58
3
votes
2 answers

Catch different Exception types

I have a very simple function to check whether an Entity exists in a bundle: public function checkExists($bundle, $val) { try{ $this->em->getRepository($bundle.':'.$val); }catch (MappingException $e){ return false; } …
PrimuS
  • 2,505
  • 6
  • 33
  • 66
3
votes
1 answer

Try Catch not catching "error : unknown IO error" - I/O warning : failed to load external entity

The code underneath is part of a function. The getLatestFileName function gets a correct fileName (locally stored). The error is caused by the tryCatch expression: result <- try(xbrlDoAll...) Even though I tried to catch it with a try function and a…
Bala
  • 31
  • 3
3
votes
4 answers

Point of try catch finally blocks?

What is the difference between using finally void ReadFile(int index) { // To run this code, substitute a valid path from your local machine string path = @"c:\users\public\test.txt"; System.IO.StreamReader file = new…
bevacqua
  • 47,502
  • 56
  • 171
  • 285
3
votes
1 answer

Repeating values in loop until error disappears

I am currently using a for loop to geocode a large number of addresses using the Googleway package. Initially, I ran into issues with "500 internal server errors" stopping the execution of the loop. I was able to get around this using tryCatch().…
Sean Norton
  • 277
  • 1
  • 12