Questions tagged [error-handling]

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

Error Handling comprises design of the code that handles errors, as opposed to the code that handles the (normal) program logic in the absence of errors during program execution.

See also

26959 questions
2674
votes
52 answers

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) { return failure; } finally { …
jonny five
  • 27,200
  • 3
  • 20
  • 11
1976
votes
27 answers

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 doesn't even catch simple parse errors. For…
Abs
  • 56,052
  • 101
  • 275
  • 409
1371
votes
11 answers

How do I print an exception in Python?

How do I print the error/exception in the except: block? try: ... except: print(exception)
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
1267
votes
38 answers

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 invited to participate adding to and maintaining…
hakre
  • 193,403
  • 52
  • 435
  • 836
937
votes
21 answers

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. Is it possible to direct the permission levels to the…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
809
votes
8 answers

Automatic exit from Bash shell script on error

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 cd some_dir ./configure…
radman
  • 17,675
  • 11
  • 42
  • 58
644
votes
41 answers

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), or a failed function call, or something else…
Candidasa
  • 8,580
  • 10
  • 30
  • 31
619
votes
16 answers

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
  • 10,308
  • 8
  • 43
  • 70
619
votes
7 answers

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", "w") begin file << "#{content} \n" rescue …
Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123
611
votes
13 answers

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 new Error({'hehe':'haha'}); // throw new…
Jayapal Chandran
  • 10,600
  • 14
  • 66
  • 91
583
votes
13 answers

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 issue I am also having is that the exit statement is before…
deadcell4
  • 6,085
  • 3
  • 14
  • 10
550
votes
14 answers

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: // node v0.10.15 > var error = new Error('simple…
Jay
  • 18,959
  • 11
  • 53
  • 72
550
votes
36 answers

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

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?
Robert Deml
  • 12,390
  • 20
  • 65
  • 92
537
votes
37 answers

Fastest way to check if a string is JSON in PHP?

I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way: function isJson($string) { return ((is_string($string) && (is_object(json_decode($string)) || …
Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177
524
votes
32 answers

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.ChildProcess._handle.onexit (child_process.js:791:34) What…
laconbass
  • 17,080
  • 8
  • 46
  • 54
1
2 3
99 100