8,820 questions
-6
votes
1
answer
98
views
Wrapping a method in a try-catch block but unsure where to declare a char variable
I have this method in my program, it is meant to register the gender of the user for later on in the program (with Male and Female as the only valid options):
public static void Main(string[] args)
{
...
0
votes
2
answers
87
views
Exporting warning messages using tryCatch() but returning different value
My question is similar to this one but that returns the error, and this one which has no answers. I want to catch errors (returning NA) and warnings (returning NaN) but saving the warning message for ...
-1
votes
1
answer
167
views
Correct usage of try and except(error) in python [duplicate]
I was wondering how was the correct usage of the try execpt/execpt(err) function in python and why it's raising up this error
UnboundLocalError: cannot access local variable 'player_move'
where it ...
2
votes
1
answer
91
views
How to handle Disposing of CryptoStream after exception occurs during decrypt
C# .Net Framework 4.8.
I am using CryptoStream Reader to decrypt an encrypted datastream within a Using {} block.
If the Key used for decryption is incorrect, the CryptoStream Reader throws an ...
-1
votes
1
answer
69
views
Catching errors of model in controller method
I have a controller method which I am using to change the status of the row data in the database. But I forget to mention status field in the model file. So the status was not changing in the database....
-2
votes
1
answer
197
views
How to create a file only once when it's needed?
I'm working on a Java utility. This utility should read some input files (one or several). Each input file contains three types of strings, representing an integer, a float, and a string. The utility ...
1
vote
1
answer
49
views
Use tryCatch() in R to keep all of the error message
I have a code that produces an error (see freq(x = r, zone = p)) :
Error in `$<-.data.frame`(`*tmp*`, "zone", value = 1L) :
replacement has 1 row, data has 0
But when using tryCatch(),...
0
votes
1
answer
129
views
How to prevent Invoke-Webrequest from writing to $Error?
I use invoke-webrequest to wait until the API of a program is running and to get an id back from the response of this request. The program takes some time to startup so before the request is posted ...
1
vote
1
answer
141
views
How do I get the HTTP status code from UrlFetchApp.fetch() when it throws an error?
I am using Google Apps Script to fetch data from an external URL. When the request is successful, I can get the HTTP status code with HTTPResponse.getResponseCode. However, if the request fails with a ...
0
votes
0
answers
32
views
Webside JavaScript - Trouble with changing class and text inside try/catch statement in function [duplicate]
So, I'm currently having a lot of trouble trying to change the text and color of a certain element. Here is my code:
<!DOCTYPE html>
<html>
<head>
<link rel="icon&...
1
vote
1
answer
188
views
How to write warnings and error generated in rendering rmarkdown file in a log file?
I have a rmarkdown setup to take input of csv data and saves results in xlsx and word file. I am rendering the rmd file within trycatch to save the warnings created within in a log file. But looks ...
3
votes
1
answer
110
views
How can I catch a non-terminating error with Get-ChildItem, but still capture the returned data?
The following code works (i.e. returns the expected data from the registry), however it throws a non-terminating error due to a lack of permissions to one of the target key's subkeys, which is benign ...
0
votes
2
answers
109
views
How to throw an exception in Java that has already been caught in another catch like in Python?
In method setPhoneNumber how can I re-throw throw new InvalidPhoneNumber("Номер телефона должен состоять только из цифр") so that it could be caught as InvalidPhoneNumber?
public class App {
...
0
votes
1
answer
274
views
Unable to catch asyncio.IncompleteReadError for websocket server
I am currently working on a websocket server to allow communication between 2 computers, and I'm coding the communication between PC and server. I made a command to stop the server remotely, but when ...
0
votes
0
answers
177
views
How to properly handle nested try/catch blocks within nested stored procedures?
I have multiple layers of nested stored procedures, each with a try...catch block within them. However, I want each of these nested stored procedures to be able to properly run their own transaction ...
1
vote
1
answer
98
views
Catching errors from async function in try...catch block outside of async function [duplicate]
So I'm doing a tutorial which contains a part about asynchronous JavaScript. I feel like I have it down pretty good, but it includes this section which I feel like is wrong for catching errors?
...
-1
votes
1
answer
151
views
Timeout issue when smtp server is downl with a site using Cloudflare
I'm using Symfony\Component\Mime\Email to send emails with try/catch. Locally when the smtp server (mailhog) is down the try/catch works well. But in prod, if the smtp is down, the page loads for ...
1
vote
1
answer
65
views
Powershell - Catch [System.???] - How do I find the ??? to use?
On a particularly deep directory, the code:
$files = Get-ChildItem -Path $d.FullName -File -Recurse -ErrorAction SilentlyContinue
is resulting in
Get-Childitem : The script failed due to call depth ...
0
votes
0
answers
36
views
@react-native-community/geolocation Location request timed out
const getLocation = () => {
const result = requestLocationPermission();
const options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 10000,
};
result.then(res ...
1
vote
1
answer
49
views
(Python) cant access attribute of an object unless I check nullity, why? [closed]
A LeetCode problem which is about linked lists that goes with this structure:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = ...
0
votes
0
answers
53
views
Toast Notification not showing when replacing file in Upload Compnent of Ant design
I'm using Ant design's Upload Component in my code to enable file uploading and replacing.
Following are the props I've defined:
const uploadProps = {
beforeUpload: async (file) => {
// ...
2
votes
1
answer
86
views
OCaml try with issue
I don't anderstand the behaviour of the try ... with ... feature of OCaml.
here is a little sample to reproduce my problem :
let () =
try int_of_string "4" with
| Failure -> -1
| n -...
0
votes
2
answers
415
views
C++Builder 12.2 error: "cannot use C++ 'try' in the same function as SEH '__try'"
After a computer crash and reinstallation of C++Builder 12.2 on a new computer, some code doesn't compile any more. For example:
void __fastcall TSynCustomExporter::CopyToClipboardFormat(UINT AFormat) ...
0
votes
1
answer
147
views
Swift catch with case let
I'm trying to bridge a Rust-based networking layer written with uniffi-rs to my Swift-based Xcode project. It has some weird type of system now, but I have this until I figure out something else.
I ...
1
vote
1
answer
179
views
JPA: Why isn't entity save() working inside catch block despite @Transactional?
I am currently working with JPA. I’ve encountered an issue during development. Here’s the current situation:
itemService addItem: If the item is already owned, an exception is thrown. If the item is ...
0
votes
1
answer
214
views
Spring Boot with Rest Template, error catching errors
I stopped an instance I call using rest template to be able to catch the errors thrown. The errors are:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for
Caused by: ...
0
votes
1
answer
56
views
A php mysqli exception is ignoring numerous catch blocks until the last one (which is outside any class) [duplicate]
I have a mysqli call ($result = $this->mysqli->query($query)) in which $query is an insert statement that generates the error: "Duplicate entry 'dt' for key 'username_UNIQUE'";. I ...
0
votes
1
answer
61
views
NativeObject try-catch does not catch a timed out error
In the following code,
private bool AuthenticateUser(string userName, string password)
{
try
{
using(var entry = new DirectoryEntry("myLDAP", userName, password))
{
// ...
1
vote
1
answer
107
views
[UnhandledPromiseRejection]: Why try...catch handle promise rejection if the last promise rejects, but throws an error for intermediate rejections?
async function all(...params) {
let result = [];
for (let promise of params) {
try {
let res = await promise;
result.push(res);
} catch (e) {
result.push({
error: ...
1
vote
1
answer
66
views
How can I test the 'catch' portion of code in a try-catch, using Mockito, when the 'try' is 'Thread.Sleep()? [duplicate]
I'm using mockito to write test, but I'm really struggling with how to test this specific bit of code:
public void myMethod() {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
throw new ...
0
votes
2
answers
216
views
Is there a way to check which line or function threw the exception I caught?
I work with code which looks similar to:
try {
f1();
f2();
f3();
}
catch(Exception) {
//...
}
If in Visual Studio I set a breakpoint within the catch block, is there a way for me to ...
1
vote
2
answers
65
views
Unreachable Catch Block for IsEmptyException and IsFullException. These exceptions are never thrown from the try statement body
In my ArrayQueueTest.java file, I can't seem to figure out what's going wrong. I get the same error, which is
unreachable catch block for IsEmptyException and IsFullException
I have tried everything ...
0
votes
1
answer
75
views
Is it good practice to use try-catch with logging, throwing user defined types that are not runtime errors?
I am writing code that reads files, parses them, and stores the data into a database when a user clicks a button. I have separated each operation into functions within multiple classes, but many of ...
2
votes
1
answer
71
views
How do I perform error-handling on non-existent web image that throws a HTTP 404 error?
I am trying to create a gt table with cropped headshots of baseball players, however there is no image available for one player (Cameron Sisneros) and this causes an HTTP error 404. Ideally, absence ...
0
votes
2
answers
112
views
Is it bad code or how to test/cover it with xUnit Test?
Code coverage tells me that catch statement is not covered in the code below. This is old code, and I'm not sure why it's written this way.
How do I test it? Is it even possible? Could potential ...
1
vote
1
answer
166
views
Catching exceptions with async await and avoid unhandledRejection [duplicate]
I have a larger use case that I narrowed down to the following code snippet.
This code might not make a lot of sense however this is just to demonstrate the issue I have.
I am trying to catch the ...
2
votes
0
answers
129
views
Is there a good, general catch-all for upload errors in R Shiny that prevent the code from crashing and ignore an erroneous upload?
I'm working on an upload/download function in R Shiny for saving and retrieving user inputs into data frames and other table objects. Files are locally saved to the user machine. I'm using tryCatch() ...
0
votes
0
answers
108
views
Why not enter the "try catch", but throw an exception externally? And who is null?
Firstly,the CAN device receives message,and calling the following method
private List<string> recordList = new List<string>();//
private List<string> recordList1 = new List<string&...
1
vote
2
answers
54
views
How to assign field name in jq based on a try catch?
I have a JSON object, some keys of which have names end in .json, like this:
{
"a.json": "...",
....
}
The "..." can be either a string which fromjson can decode,...
1
vote
1
answer
101
views
Trying to catch exceptions while turning string array into ints
I have a text document with an list of numbers experated by "|".
Ex:
0|0|2
1|0|1
1|1|0
2|0|1
2|1|0
2|2|1
3|0|0
3|1|1
3|2|0
3|3|1
I am generating this though code and all ways have an extra ...
0
votes
1
answer
80
views
VSCode, Flutter: Try-Catch block doesn't catch Exception
I'm trying to catch an exception that occurs in my code line
var excel = Excel.decodeBytes(bytes);
but the error is not caught.
The compiler stops at the line and shows:
Exception:
StateError (Bad ...
0
votes
2
answers
342
views
Getting an error in console even though I have used try/catch and async/await
/* the code that is doing the API call, account.get() is an endpoint provided by Appwrite to get current user session data */
export async function getCurrentUser() {
try {
const user = await ...
1
vote
0
answers
73
views
Why is my thread blocked by this try block?
So I am self-taught and green on handling requests, but it seems to me that in the case of no request body, the BufferedReader should output null if I call .readLine() again after running this kind of ...
0
votes
2
answers
432
views
When will a laravel model creation fail without an exception?
I am adding a store method to a controller that will create and save a new model to the database using the following code:
public function store(Request $request)
{
$validated = $request->...
0
votes
1
answer
40
views
How do I get a try / exception statement to continue? [duplicate]
I need this to rerun the initial inpput question if it gets a value that is unacceptable.
try:
hours = float(input("Please enter your hours worked: "))
if hours < 1 :
...
0
votes
1
answer
54
views
Appropriate way to handle exception in Java n-tier application
I have three layers in my application Controller, Service and DAO. My controller and service layers are in spring meanwhile DAO layer is in Hibernate 6. My question is what is most appropriate way to ...
1
vote
0
answers
183
views
C++ sigbus error when trying to catch an exception
I have come across an interesting case, where C++ gives me a bus error, when I am trying to catch an exception.
I created a minimal example to reproduce the error:
#include <iostream>
using ...
0
votes
0
answers
63
views
Nested Try/Catch alternative [duplicate]
I have a need to attempt to convert a date from the registry to a [Datetime] so that I can do operations with it, and the date format is variable, because Autodesk. I also need to be able to throw ...
2
votes
1
answer
123
views
How to get the current exception object in C++ Builder (replacement for ExceptObject)?
I am looking for a function/code that returns the current exception object. In other words, the exception object that represents the exception currently being handled (by the catch block).
For example:...
0
votes
0
answers
71
views
Catch block not catching file load faillure when file is blocked by applocker / wdac
try
{
var appcontrolHeartbeat = new Class1();
}
catch (FileLoadException e)
{
log.Info(
$"...