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

As described in the Xcode 8 beta 6 release notes, Swift-defined error types can provide localized error descriptions by adopting the new LocalizedError protocol. In your case: public enum MyError: Error { case customError } extension MyError: LocalizedError { public var errorDescription: String? { switch self { case .customError: return NSLocalizedString(“A user-friendly description of the … Read more

Error handling in Bash [closed]

Use a trap! tempfiles=( ) cleanup() { rm -f “${tempfiles[@]}” } trap cleanup 0 error() { local parent_lineno=”$1″ local message=”$2″ local code=”${3:-1}” if [[ -n “$message” ]] ; then echo “Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}” else echo “Error on or near line ${parent_lineno}; exiting with status ${code}” fi exit … Read more

Are there any standard exit status codes in Linux?

Part 1: Advanced Bash Scripting Guide As always, the Advanced Bash Scripting Guide has great information: (This was linked in another answer, but to a non-canonical URL.) 1: Catchall for general errors 2: Misuse of shell builtins (according to Bash documentation) 126: Command invoked cannot execute 127: “command not found” 128: Invalid argument to exit … Read more

Why is “except: pass” a bad programming practice?

As you correctly guessed, there are two sides to it: Catching any error by specifying no exception type after except, and simply passing it without taking any action. My explanation is “a bit” longer—so tl;dr it breaks down to this: Don’t catch any error. Always specify which exceptions you are prepared to recover from and … Read more

Can I try/catch a warning?

Set and restore error handler One possibility is to set your own error handler before the call and restore the previous error handler later with restore_error_handler(). set_error_handler(function() { /* ignore errors */ }); dns_get_record(); restore_error_handler(); You could build on this idea and write a re-usable error handler that logs the errors for you. set_error_handler([$logger, ‘onSilencedError’]); … Read more

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

PHP stores error logs in /var/log/apache2 if PHP is an apache2 module. Shared hosts are often storing log files in your root directory /log subfolder. But…if you have access to a php.ini file you can do this: error_log = /var/log/php-scripts.log According to rinogo‘s comment: If you’re using cPanel, the master log file you’re probably looking … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)