Questions tagged [error-handling]
Programming language constructs designed to handle errors signaled by error codes, exceptions or other language specific means.
error-handling
27,492
questions
2703
votes
52
answers
621k
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) {
...
2017
votes
27
answers
3.6m
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 ...
1451
votes
11
answers
2.1m
views
How do I print an exception in Python?
How do I print the error/exception in the except: block?
try:
...
except:
print(exception)
1286
votes
39
answers
281k
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 ...
981
votes
21
answers
688k
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.
...
834
votes
8
answers
435k
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
...
651
votes
41
answers
715k
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),...
651
votes
18
answers
676k
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.
640
votes
14
answers
564k
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 ...
631
votes
13
answers
914k
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 to echo a specific output?
I'm thinking of it being:
if [ $? -eq 1 ]; then
echo "blah blah blah"
fi
The issue I am ...
630
votes
7
answers
513k
views
Begin, Rescue and Ensure in Ruby?
I was wondering if ensure was the Ruby equivalent of finally in C#? Should I have:
file = File.open("myFile.txt", "w")
begin
file << "#{content} \n"
rescue
# ...
606
votes
15
answers
229k
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:
...
556
votes
36
answers
199k
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?
540
votes
31
answers
786k
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....
532
votes
27
answers
222k
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 ...