exception-handling

Is it ever advantageous to use 'goto' in a language that supports loops and functions? If so, why?

ぐ巨炮叔叔 提交于 2019-12-17 02:08:07
问题 I've long been under the impression that goto should never be used if possible. While perusing libavcodec (which is written in C) the other day, I noticed multiple uses of it. Is it ever advantageous to use goto in a language that supports loops and functions? If so, why? 回答1: There are a few reasons for using the "goto" statement that I'm aware of (some have spoken to this already): Cleanly exiting a function Often in a function, you may allocate resources and need to exit in multiple places

When to catch java.lang.Error?

。_饼干妹妹 提交于 2019-12-16 20:13:54
问题 In what situations should one catch java.lang.Error on an application? 回答1: Generally, never. However, sometimes you need to catch specific Errors. If you're writing framework-ish code (loading 3rd party classes), it might be wise to catch LinkageErrors (no class def found, unsatisfied link, incompatible class change). I've also seen some stupid 3rd-party code throwing sublcasses of Errors, so you'll have to handle these either. By the way, I'm not sure it isn't possible to recover from

Need to handle uncaught exception and send log file

北慕城南 提交于 2019-12-16 20:09:09
问题 UPDATE: Please see "accepted" solution below When my app creates an unhandled exception, rather than simply terminating, I'd like to first give the user an opportunity to send a log file. I realize that doing more work after getting a random exception is risky but, hey, the worst is the app finishes crashing and the log file doesn't get sent. This is turning out to be trickier than I expected :) What works: (1) trapping the uncaught exception, (2) extracting log info and writing to a file.

Why catch and rethrow an exception in C#?

安稳与你 提交于 2019-12-16 20:08:45
问题 I'm looking at the article C# - Data Transfer Object on serializable DTOs. The article includes this piece of code: public static string SerializeDTO(DTO dto) { try { XmlSerializer xmlSer = new XmlSerializer(dto.GetType()); StringWriter sWriter = new StringWriter(); xmlSer.Serialize(sWriter, dto); return sWriter.ToString(); } catch(Exception ex) { throw ex; } } The rest of the article looks sane and reasonable (to a noob), but that try-catch-throw throws a WtfException... Isn't this exactly

Unable to determine the principle end of the relationship - multiple added entities may have the same primary key

岁酱吖の 提交于 2019-12-16 18:06:58
问题 Sets have Cards and Sets. Here's what I have in my model, using EF Code First: public class Set { // Primitive Properties [Required] [Key] public virtual int SetId { get; set; } // Navigation Properties [Required] public virtual List<Set> Sets { get; set; } // Navigation Properties [ForeignKey("ParentSet")] public int ParentSetId { get; set; } public virtual Set ParentSet { get; set; } } Then for Cards: public class Card { // Primitive Properties [Required] [Key] public virtual int CardId {

When would you prefer to declare an exception rather than handling it in Java?

删除回忆录丶 提交于 2019-12-14 04:19:12
问题 I know we can declare the exception for our method if we want it to be handled by the calling method. This will even allow us to do stuff like write to the OutputStream without wrapping the code in try/catch block if the enclosing method throws IOException. My question is: Can anyone provide an instance where this is usually done where you'd like the calling method to handle the exception instead of the current method? Edit: I meant calling method instead of super class in the last line. 回答1:

C# Uncaught exception in unit test

十年热恋 提交于 2019-12-14 03:45:23
问题 I'm encountering a very strange issue while debugging a unit test. If I debug the unit test (ctrl+r ctrl+t) I am getting an uncaught exception. If I just run the unit test (ctrl+r t) I do not get this exception. The uncaught exception is a NHibernate.ByteCode.ProxyFactoryFactoryNotConfiguredException. Stack trace: at NHibernate.Bytecode.AbstractBytecodeProvider.get_ProxyFactoryFactory() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Bytecode\AbstractBytecodeProvider.cs:line 32 at NHibernate

handle global errors asmx

谁说我不能喝 提交于 2019-12-14 03:23:59
问题 I have class that implements asmx service. class AsmxService{ public string Method(int i){.....} ....} I omit some attributes, but can provide full code if you find it necessary. If I get exception into function Method, it's not a problem: just use try-catch. But what should we do, if error occured outside the function. For example, client passed invalid int parameter or something else. In that case on client side I get message about exception. But I d'like to hide all details of error and

Chain of responsibility in ExceptionMiddleware .net core

独自空忆成欢 提交于 2019-12-14 02:25:58
问题 is it possible to implement something similar to chain of responsibility pattern in .net core middleware which catches exceptions? Because I wanted to Handle exceptions globally and take them to their handlers. Example try { } catch(CustomException1 ex) { } catch(CustomException2 ex) { } ... The middleware grows really fast and it will be hard to maintain later. I wanted to try{} catch(Exception e) { Handle(e); } and make Handlers for each Exception, for example handler for NullReference etc.

Exception for ConnectionResetError: [Errno 54] Connection reset by peer

假装没事ソ 提交于 2019-12-14 02:24:31
问题 I cannot successfully build an exception for the error I am receiving: ConnectionResetError: [Errno 54] Connection reset by peer Here is my code: try: for img in soup.findAll('img', {'class': 'thisclass'}): print('Image #:' + str(counter) + ' URL: ' + img['src']) myurl = img['src'] urllib.request.urlretrieve(str(myurl), str(mypath)+str(foldername)+'/webp/'+str(foldername)+str(counter)+'.webp') im = Image.open(str(mypath)+str(foldername)+'/webp/'+ str(foldername) +str(counter)+'.webp').convert