Questions tagged [error-handling]

Programming language constructs designed to handle errors signaled by error codes, exceptions or other language specific means.

error-handling
Filter by
Sorted by
Tagged with
2695 votes
52 answers
614k views

Does a finally block always get executed in Java?

Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is? try { something(); return success; } catch (Exception e) { ...
jonny five's user avatar
  • 27.4k
2000 votes
27 answers
3.5m views

How do I get PHP errors to display?

I have checked my PHP ini file (php.ini) and display_errors is set and also error reporting is E_ALL. I have restarted my Apache webserver. I have even put these lines at the top of my script, and it ...
Abs's user avatar
  • 56.9k
1428 votes
11 answers
2.0m views

How do I print an exception in Python?

How do I print the error/exception in the except: block? try: ... except: print(exception)
TIMEX's user avatar
  • 265k
1283 votes
39 answers
279k views

Reference - What does this error mean in PHP?

What is this? This is a number of answers about warnings, errors, and notices you might encounter while programming PHP and have no clue how to fix them. This is also a Community Wiki, so everyone is ...
962 votes
21 answers
663k views

How can I exclude all "permission denied" messages from "find"?

I need to hide all permission denied messages from: find . > files_and_folders I am experimenting when such message arises. I need to gather all folders and files, to which it does not arise. ...
Léo Léopold Hertz 준영's user avatar
822 votes
8 answers
423k views

Automatic exit from Bash shell script on error [duplicate]

I've been writing some shell script and I would find it useful if there was the ability to halt the execution of said shell script if any of the commands failed. See below for an example: #!/bin/bash ...
radman's user avatar
  • 18k
649 votes
41 answers
706k views

How can I get useful error messages in PHP?

Quite often I will try and run a PHP script and just get a blank screen back. No error message; just an empty screen. The cause might have been a simple syntax error (wrong bracket, missing semicolon),...
Candidasa's user avatar
  • 8,650
637 votes
18 answers
656k views

Is there a TRY CATCH command in Bash

I'm writing a shell script and need to check that a terminal app has been installed. I want to use a TRY/CATCH command to do this unless there is a neater way.
Lee Probert's user avatar
  • 10.5k
629 votes
13 answers
546k views

What is the difference between `throw new Error` and `throw someObject`?

I want to write a common error handler which will catch custom errors thrown on purpose at any instance of the code. When I did throw new Error('sample') like in the following code try { throw ...
Jayapal Chandran's user avatar
625 votes
7 answers
506k views

Begin, Rescue and Ensure in Ruby?

I've recently started programming in Ruby, and I am looking at exception handling. I was wondering if ensure was the Ruby equivalent of finally in C#? Should I have: file = File.open("myFile.txt", "...
Lloyd Powell's user avatar
  • 18.5k
614 votes
13 answers
875k views

How to check the exit status using an 'if' statement

What would be the best way to check the exit status in an if statement in order to echo a specific output? I'm thinking of it being: if [ $? -eq 1 ] then echo "blah blah blah" fi The ...
deadcell4's user avatar
  • 6,405
587 votes
15 answers
219k views

Is it not possible to stringify an Error using JSON.stringify?

Reproducing the problem I'm running into an issue when trying to pass error messages around using web sockets. I can replicate the issue I am facing using JSON.stringify to cater to a wider audience: ...
Jay's user avatar
  • 19.4k
555 votes
36 answers
197k views

Should a retrieval method return 'null' or throw an exception when it can't produce the return value? [closed]

I am using java language,I have a method that is supposed to return an object if it is found. If it is not found, should I: return null throw an exception other Which is the best practise or idiom?
536 votes
31 answers
763k views

How do I debug "Error: spawn ENOENT" on node.js?

When I get the following error: events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:1000:11) at Process....
laconbass's user avatar
  • 17.4k
526 votes
16 answers
210k views

Pipe output and capture exit status in Bash

I want to execute a long running command in Bash, and both capture its exit status, and tee its output. So I do this: command | tee out.txt ST=$? The problem is that the variable ST captures the ...
flybywire's user avatar
  • 267k
524 votes
27 answers
218k views

What's a good way to extend Error in JavaScript?

I want to throw some things in my JS code and I want them to be instanceof Error, but I also want to have them be something else. In Python, typically, one would subclass Exception. What's the ...
Josh Gibson's user avatar
  • 22.3k
501 votes
19 answers
640k views

What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?

My Swift program is crashing with EXC_BAD_INSTRUCTION and one of the following similar errors. What does this error mean, and how do I fix it? Fatal error: Unexpectedly found nil while unwrapping ...
475 votes
30 answers
1.3m views

Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)

I am on shared hosting and have cPanel, Apache, and PHP is run by FastCGI. Where does PHP store the error log? Is there another way I can find the error log on a shared hosting environment instead of ...
PHPLOVER's user avatar
  • 7,097
421 votes
14 answers
272k views

Can I try/catch a warning?

I need to catch some warnings being thrown from some php native functions and then handle them. Specifically: array dns_get_record ( string $hostname [, int $type= DNS_ANY [, array &$authns [...
user121196's user avatar
  • 30.5k
417 votes
19 answers
340k views

Why is "except: pass" a bad programming practice?

I often see comments on other Stack Overflow questions about how the use of except: pass is discouraged. Why is this bad? Sometimes I just don't care what the errors are and I want to just continue ...
Vader's user avatar
  • 6,526
397 votes
9 answers
348k views

Is 418 "I'm a teapot" really an HTTP response code?

Is 418 "I'm a teapot" really an HTTP response code? There are various references to this on the internet, including in lists of response codes, but I can't figure out whether it's a weird joke.
Mohan's user avatar
  • 7,971
389 votes
4 answers
326k views

Raise warning in Python without interrupting program

I am trying to raise a Warning in Python without making the program crash / stop / interrupt. I use the following simple function to check if the user passed a non-zero number to it. If so, the ...
Tomas Novotny's user avatar
386 votes
10 answers
1.4m views

400 BAD request HTTP error code meaning?

I have a JSON request which I'm posting to a HTTP URL. Should this be treated as 400 where requestedResource field exists but "Roman" is an invalid value for this field? [{requestedResource:"Roman"...
Phoenix's user avatar
  • 8,793
384 votes
12 answers
353k views

Are there any standard exit status codes in Linux?

A process is considered to have completed correctly in Linux if its exit status was 0. I've seen that segmentation faults often result in an exit status of 11, though I don't know if this is simply ...
Nathan Fellman's user avatar
327 votes
15 answers
538k views

What's the cause of the error 'getaddrinfo EAI_AGAIN'?

My server threw this today, which is a Node.js error I've never seen before: Error: getaddrinfo EAI_AGAIN my-store.myshopify.com:443 at Object.exports._errnoException (util.js:870:11) at ...
ThomasReggi's user avatar
  • 57.2k
325 votes
7 answers
113k views

How to provide a localized description with an Error type in Swift?

I am defining a custom error type with Swift 3 syntax and I want to provide a user-friendly description of the error which is returned by the localizedDescription property of the Error object. How can ...
Evgenii's user avatar
  • 36.8k
301 votes
20 answers
488k views

How do I solve "error: externally-managed-environment" every time I use pip 3?

Error message: error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package ...
Apoliticalboy's user avatar
295 votes
15 answers
451k views

Error handling in Bash [closed]

What is your favorite method to handle errors in Bash? The best example of handling errors I have found on the web was written by William Shotts, Jr at http://www.linuxcommand.org. He suggests ...
295 votes
26 answers
267k views

live output from subprocess command

I'm using a python script as a driver for a hydrodynamics code. When it comes time to run the simulation, I use subprocess.Popen to run the code, collect the output from stdout and stderr into a ...
DilithiumMatrix's user avatar
281 votes
9 answers
446k views

How do I log errors and warnings into a file?

How do I turn on all error and warnings and log them to a file, but to set up all of that within the script (not changing anything in php.ini)? I want to define a file name and so that all errors and ...
Gorep's user avatar
  • 2,835
276 votes
13 answers
767k views

How to get the jQuery $.ajax error response text?

I am sending an error response to my jQuery. However, I can not get the response text (in the example below this would be Gone to the beach) The only thing jQuery says is 'error'. See this example ...
jantimon's user avatar
  • 37.4k
248 votes
3 answers
100k views

Catch all JavaScript errors and send them to server [closed]

I wondered if anyone had experience in handling JavaScript errors globally and send them from the client browser to a server. I think my point is quite clear, I want to know every exception, error, ...
Olivier Girardot's user avatar
242 votes
8 answers
517k views

How do I catch an Ajax query post error?

I would like to catch the error and show the appropriate message if the Ajax request fails. My code is like the following, but I could not manage to catch the failing Ajax request. function ...
TTCG's user avatar
  • 9,005
239 votes
13 answers
246k views

Log exception with traceback in Python

How can I log my Python exceptions? try: do_something() except: # How can I log my exception here, complete with its traceback?
TIMEX's user avatar
  • 265k
230 votes
22 answers
654k views

Deploying website: 500 - Internal server error

I am trying to deploy an ASP.NET application. I have deployed the site to IIS, but when visiting it with the browser, it shows me this: Server Error 500 - Internal server error. There is a problem ...
Jacob Jedryszek's user avatar
227 votes
11 answers
184k views

JAX-RS / Jersey how to customize error handling?

I'm learning JAX-RS (aka, JSR-311) using Jersey. I've successfuly created a Root Resource and am playing around with parameters: @Path("/hello") public class HelloWorldResource { @GET @...
Mark Renouf's user avatar
  • 30.9k
223 votes
13 answers
99k views

Cryptic "Script Error." reported in Javascript in Chrome and Firefox

I have a script that detects Javascript errors on my website and sends them to my backend for reporting. It reports the first error encountered, the supposed line number, and the time. EDIT to ...
Mike Sherov's user avatar
  • 13.4k
220 votes
11 answers
600k views

Error: could not find function ... in R

This is meant to be a FAQ question, so please be as complete as possible. The answer is a community answer, so feel free to edit if you think something is missing. This question was discussed and ...
214 votes
3 answers
107k views

How to create an exit message

Is there a one line function call that quits the program and displays a message? I know in Perl it's as simple as: die("Message goes here") I'm tired of typing this: puts "Message goes here" exit
Chris Bunch's user avatar
  • 88.7k
212 votes
21 answers
32k views

Is assert evil? [closed]

The Go language creators write: Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error ...
207 votes
15 answers
367k views

Detailed 500 error message, ASP + IIS 7.5

IIS 7.5 , 2008rc2, classic asp, 500 error msg: The page cannot be displayed because an internal server error has occurred. I need to know how to configure IIS to get a more detailed error. I've ...
egidiocs's user avatar
  • 2,757
204 votes
1 answer
62k views

try, try! & try? what’s the difference, and when to use each?

In Swift 2.0, Apple introduced a new way to handle errors (do-try-catch). And few days ago in Beta 6 an even newer keyword was introduced (try?). Also, knew that I can use try!. What's the difference ...
Abdurrahman's user avatar
  • 6,466
202 votes
7 answers
157k views

How can I make use of Error boundaries in functional React components?

I can make a class an error boundary in React by implementing componentDidCatch. Is there a clean approach to making a functional component into an error boundary without converting it into a class? ...
Dancrumb's user avatar
  • 27k
195 votes
6 answers
172k views

How to capture no file for fs.readFileSync()?

Within node.js readFile() shows how to capture an error, however there is no comment for the readFileSync() function regarding error handling. As such, if I try to use readFileSync() when there is no ...
Metalskin's user avatar
  • 4,138
195 votes
13 answers
95k views

Error-Handling in Swift-Language

I haven't read too much into Swift but one thing I noticed is that there are no exceptions. So how do they do error handling in Swift? Has anyone found anything related to error-handling?
peko's user avatar
  • 11.3k
186 votes
23 answers
148k views

Error handling in C code

What do you consider "best practice" when it comes to error handling errors in a consistent way in a C library. There are two ways I've been thinking of: Always return error code. A typical function ...
Laserallan's user avatar
  • 11.1k
184 votes
6 answers
216k views

Raise error in a Bash script

I want to raise an error in a Bash script with message "Test cases Failed !!!". How to do this in Bash? For example: if [ condition ]; then raise error "Test cases failed !!!" fi
Naveen Kumar's user avatar
  • 2,730
183 votes
6 answers
207k views

When should I use Write-Error vs. Throw? Terminating vs. non-terminating errors

Looking at a Get-WebFile script over on PoshCode, http://poshcode.org/3226, I noticed this strange-to-me contraption: $URL_Format_Error = [string]"..." Write-Error $URL_Format_Error return What is ...
Bill Barry's user avatar
  • 3,463
182 votes
5 answers
88k views

How do I log ALL exceptions globally for a C# MVC4 WebAPI app?

Background I am developing an API Service Layer for a client and I have been requested to catch and log all errors globally. So, while something like an unknown endpoint (or action) is easily ...
Matt Cashatt's user avatar
  • 23.8k
179 votes
31 answers
436k views

Eclipse returns error message "Java was started but returned exit code = 1"

This is a picture of the error code Here is the content of the error message: Java was started but returned exit code=1 C:\WINDOWS\system32\javaw.exe -Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx768m -...
Vladislav Bogdanov's user avatar

1
2 3 4 5
547