exception-handling

Jython does not catch Exceptions

ε祈祈猫儿з 提交于 2019-12-13 05:38:25
问题 Jython doesn't have the -m option, and it raises an error with from .utils import * . The solution is not to use relative path sys.path.insert(0, os.path.dirname(__file__)) from utils import * As I need to use the code both Jython and CPython, I came up with this command: try: from .utils import * except Exception: # Jython or Python with python context/context.py invocation sys.path.insert(0, os.path.dirname(__file__)) from utils import * However, Jython doesn't seem to catch the exception,

How to deal with returning an object and handling errors

久未见 提交于 2019-12-13 05:35:43
问题 Thanks for checking out my question. I have the following code for a java deck. I want to step away from arrays and toy code and try using best practice and object oriented principles for this one, I'm aware that I can do this in a much simpler, but less re-usable, manner. The end goal is to create a cardgame framework which I can use to deal with the mundane parts of deck management while concentrating on the implementation of different games. I'm having an issue with my error handling. My

How to do exception handling in my code

前提是你 提交于 2019-12-13 05:22:51
问题 I just learned about exception handling. So, I am still getting use to it. I know how to do the basic exception handling like entering in a correct value for division and having it throw a DividebyZeroException if a incorrect value is entered. But I need help some help on doing the following: Create an exception handling to throw an error if 1) The number of integer in each row are not equal to each other for example: Matrix = [ 3 4; 9 8 1] should be : matrix = [ 3 4 2; 9 8 1] 2) the

Would I want to throw an exception or an error in this PHP script?

荒凉一梦 提交于 2019-12-13 04:56:42
问题 I have a PHP script that runs database queries. Now, if a query fails, should I trigger an error or throw an exception? I noticed that if I do the latter, the script execution will stop after facing the exception. My code is as follows: if (!$this->connection[0]->query($this->query)) throw new Exception($this->connection[0]->error); What are the pros and cons of using exceptions for this kind of cases (failed queries)? 回答1: depends on your general error handling strategy and the queries

Operator '/' can't be applied to operands of types 'decimal' and 'double' - NCalc

↘锁芯ラ 提交于 2019-12-13 04:55:46
问题 I'm trying to run this formula in NCalc: "( Abs([a] - [b]) / ( ([a] + [b]) / 2.0 ) ) * 100" I get the error: Operator '/' can't be applied to operands of types 'decimal' and 'double' The [a] and [b] parameters are passed as Decimals. I tried putting 'm' on the 2 and 100 like so: "( Abs([a] - [b]) / ( ([a] + [b]) / 2m ) ) * 100m" But it throws an exception: Additional information: extraneous input 'm' expecting ')' at line 1:36 I followed this question, but it didn't help me. The same question

Python Lxml: Adding and deleting tags

懵懂的女人 提交于 2019-12-13 04:33:18
问题 I am attempting to add and remove tags in an xml tree (snip below). I have a dict of boolean values that I use to determine whether to add or remove a tag. If the value is true, and the element does not exist, it creates the tag (and its parent if it doesn't exist). If false, it deletes the value. However, it doesn't seem to work, and I can't find out why. <Assets> <asset name="Adham"> <pos> <x>27913.769923</x> <y>5174.627773</y> </pos> <GFX> <space>P03.png</space> <exterior>snow.png<

Python how to add exception?

删除回忆录丶 提交于 2019-12-13 04:32:13
问题 @martineau I have updated my codes, is this what you meant ? How do i handle KeyError instead of NameError ? url = "http://app2.nea.gov.sg/anti-pollution-radiation-protection/air-pollution/psi/psi-readings-over-the-last-24-hours" web_soup = soup(urllib2.urlopen(url)) table = web_soup.find(name="div", attrs={'class': 'c1'}).find_all(name="div")[4].find_all('table')[0] data = {} cur_time = datetime.datetime.strptime("12AM", "%I%p") for tr_index, tr in enumerate(table.find_all('tr')): if 'Time'

Send catched ajax exception back to server to perform logging?

前提是你 提交于 2019-12-13 04:21:14
问题 i have an MVC3 application and i'm using Elmah to store the errors in a mysql database and even send those errors by email. This is working perfectly, now i have this javascript code in my main layout: $(document).ajaxError(function (e, xhr, settings, exception) { //SEND BACK TO SERVER THE EXCEPTION }); Now, what i want to do is to get the catched exception (the ajax exception) and send back to server to a method that stores that exception with Elmah. Is that possible? If it isn't what choice

Juding whether an exception is exceptional

﹥>﹥吖頭↗ 提交于 2019-12-13 03:47:51
问题 It's a pretty popular and well known phrase that you should "only catch/throw exceptions which are exceptional". However, how is an "exceptional" exception determined? For example, a bad password is very routine in logging into a service, so this is not exceptional. Statistics for a web app would probably show something like one bad login attempt for every 5 attempts (from no specific user). Likewise, with attempting to go to a checkout with a basket in an online store, this could be very

How to throw a exception that doesnt inherit from Exception?

折月煮酒 提交于 2019-12-13 03:47:03
问题 I would like to test some exception handling logic in the empty catch block of the below code. try { //Do Some stuff that throws a exception //This is the code i need } catch (Exception) { //Handle things that inherits from Exception } catch { //Handle things that dont inherits from Exception //Want to test this code } 回答1: Starting with CLR 2.0 this is not a scenario that you need to worry about. The CLR will now automatically wrap all exceptions which do not derive from System.Exception