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

22833 questions
2506
votes
49 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
  • 25,492
  • 3
  • 18
  • 11
1836
votes
28 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
  • 51,038
  • 92
  • 260
  • 394
1192
votes
36 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
  • 178,314
  • 47
  • 389
  • 754
906
votes
9 answers

How to print an exception in Python?

try: something here except: print('the whatever error occurred.') How can I print the error/exception in my except: block?
TIMEX
  • 217,272
  • 324
  • 727
  • 1,038
826
votes
17 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 준영
  • 119,377
  • 159
  • 417
  • 655
669
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
  • 14,904
  • 9
  • 38
  • 56
613
votes
44 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,212
  • 10
  • 28
  • 31
577
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
  • 16,975
  • 15
  • 80
  • 119
516
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
  • 11,820
  • 19
  • 61
  • 85
457
votes
11 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
  • 8,687
  • 14
  • 62
  • 85
448
votes
15 answers

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 exit status of tee and not of command. How can I…
flybywire
  • 232,954
  • 184
  • 384
  • 491
447
votes
11 answers

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 an Optional value or Fatal error: Unexpectedly…
jtbandes
  • 104,858
  • 34
  • 217
  • 242
434
votes
32 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
  • 23,368
  • 41
  • 108
  • 164
430
votes
14 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
  • 7,847
  • 8
  • 35
  • 49
429
votes
25 answers

Where does PHP store the error log? (php5, apache, fastcgi, cpanel)

I am on shared hosting and have Cpanel, Apache, PHP is run by fastcgi. Where does PHP store the error log? Is there any other way I can find the error log on shared hosting environment instead of having to go through entire site structure to look…
PHPLOVER
  • 6,539
  • 18
  • 34
  • 52
1
2 3
99 100