Is assert evil? [closed]

No, there’s nothing wrong with assert as long as you use it as intended. That is, it’s supposed to be for catching cases that “can’t happen”, during debugging, as opposed to normal error handling. Assert: A failure in the program’s logic itself. Error Handling: An erroneous input or system state not due to a bug … Read more

Log exception with traceback in Python

Use logging.exception from within the except: handler/block to log the current exception along with the trace information, prepended with a message. import logging LOG_FILENAME = ‘/tmp/logging_example.out’ logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG) logging.debug(‘This message should go to the log file’) try: run_my_stuff() except: logging.exception(‘Got exception on main handler’) raise Now looking at the log file, /tmp/logging_example.out: DEBUG:root:This message should … Read more

Cryptic “Script Error.” reported in Javascript in Chrome and Firefox

The “Script error.” happens in Firefox, Safari, and Chrome when an exception violates the browser’s same-origin policy – i.e. when the error occurs in a script that’s hosted on a domain other than the domain of the current page. This behavior is intentional, to prevent scripts from leaking information to external domains. For an example … Read more

JAX-RS / Jersey how to customize error handling?

There are several approaches to customize the error handling behavior with JAX-RS. Here are three of the easier ways. The first approach is to create an Exception class that extends WebApplicationException. Example: public class NotAuthorizedException extends WebApplicationException { public NotAuthorizedException(String message) { super(Response.status(Response.Status.UNAUTHORIZED) .entity(message).type(MediaType.TEXT_PLAIN).build()); } } And to throw this newly create Exception you simply: … Read more

How do I catch an Ajax query post error?

Since jQuery 1.5 you can use the deferred objects mechanism: $.post(‘some.php’, {name: ‘John’}) .done(function(msg){ }) .fail(function(xhr, status, error) { // error handling }); Another way is using .ajax: $.ajax({ type: “POST”, url: “some.php”, data: “name=John&location=Boston”, success: function(msg){ alert( “Data Saved: ” + msg ); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(“some error”); } });

live output from subprocess command

TLDR for Python 3: import subprocess import sys with open(“test.log”, “wb”) as f: process = subprocess.Popen(your_command, stdout=subprocess.PIPE) for c in iter(lambda: process.stdout.read(1), b””): sys.stdout.buffer.write(c) f.buffer.write(c) You have two ways of doing this, either by creating an iterator from the read or readline functions and do: import subprocess import sys # replace “w” with “wb” for … Read more

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