exception-handling

Custom exception vs built in exception with very descriptive message

为君一笑 提交于 2020-01-14 10:44:07
问题 I came across an interesting situation today: I have a small app with a settings file, which is well documented in the documentation, but if the file is not there, what would be better: throw a filenotfoundexception and give a very depressive message that the settings file is not available, or create a custom exception (already, the disadvantage is the work in doing this, even though it'll take 10 minutes) called SettingsFileNotFoundException. This will give it away immediately, what the

Is it safe to store an instance of an Exception and reuse it?

大憨熊 提交于 2020-01-14 07:13:52
问题 Is it safe to: public class Widget { private static final IllegalStateException LE_EXCEPTION = new IllegalStateException("le sophisticated way"); ... public void fun() { // some logic here, that may throw throw LE_EXCEPTION; } .... } keep an instance of an exception use it whenever needed (throw) instead of throwing a new exception each time? I am interested if it's safe By safe I mean: no memory corruption, no additional exceptions thrown by JVM, by missing classes, no bad classes loaded (..

asp.net + exceptions and redirecting

我与影子孤独终老i 提交于 2020-01-14 06:19:30
问题 My intention is to log an error(I am using Log4Net) when an exception is caught and redirect to a pretty looking page with some error message. I have a class that returns a Type T object , mostly a DataSet. In my Catch statement I wrote this, it works but I am not sure if there's a more appropriate way of handling, can someone please advice. Thanks. Note that the throw cannot be omitted because the class has a return type.: catch (Exception ex) { log.Error(ex); HttpContext.Current.Response

asp.net + exceptions and redirecting

微笑、不失礼 提交于 2020-01-14 06:18:06
问题 My intention is to log an error(I am using Log4Net) when an exception is caught and redirect to a pretty looking page with some error message. I have a class that returns a Type T object , mostly a DataSet. In my Catch statement I wrote this, it works but I am not sure if there's a more appropriate way of handling, can someone please advice. Thanks. Note that the throw cannot be omitted because the class has a return type.: catch (Exception ex) { log.Error(ex); HttpContext.Current.Response

How to convert an exception into an NSError object

南楼画角 提交于 2020-01-14 04:50:11
问题 I want to convert the message of an exception into an NSError object so that I can use it within a try-catch block (I'm actually working on a native iOS module for React Native). RCT_EXPORT_METHOD(myMethod:(NSDictionary *)dict resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { @try { // Do something which could throw something (NS Error or NS Exception) resolve(nil); } @catch (NSException *exception) { // HERE I WANT TO TRANSFORM THE EXCEPTION exception INTO AN

What's the difference between Software-Generated Interrupt and Software-Generated Exception?

雨燕双飞 提交于 2020-01-14 04:23:52
问题 I am reading the Intel Manual 3A Chapter 6 Interrupt and Exception Handling. Interrupt and Exception have 3 sources respectively. For Software-Generated Interrupt, it says: The INT n instruction permits interrupts to be generated from within software by supplying an interrupt vector number as an operand. For example, the INT 35 instruction forces an implicit call to the interrupt handler for interrupt 35. Any of the interrupt vectors from 0 to 255 can be used as a parameter in this

CakePHP 3: Exception handling / serialization in a RESTful API

不想你离开。 提交于 2020-01-14 02:59:22
问题 I'm building a JSON RESTful API with CakePHP3, but I'm not sure what is the best approach to handle errors and give the client information about the error. My approach so far is to throw a HttpException if (for example) saving an entity fails due to validation errors. In my controller I have the following: if (!$this->Categories->save($categoryEntity)) { throw new InternalErrorException('Saving failed'); } $this->set('status', 'Everything fine!'); $this->set('_serialize', true); If the saving

CakePHP 3: Exception handling / serialization in a RESTful API

半腔热情 提交于 2020-01-14 02:59:06
问题 I'm building a JSON RESTful API with CakePHP3, but I'm not sure what is the best approach to handle errors and give the client information about the error. My approach so far is to throw a HttpException if (for example) saving an entity fails due to validation errors. In my controller I have the following: if (!$this->Categories->save($categoryEntity)) { throw new InternalErrorException('Saving failed'); } $this->set('status', 'Everything fine!'); $this->set('_serialize', true); If the saving

Unhandled DivideByZero exception from an external DLL - C#

旧巷老猫 提交于 2020-01-13 19:20:09
问题 I have a C# (.net 4.0) program, whose main is calling methods from an external FTP library - a dll the project references. The logic is in a try-catch block, and the catch prints the error. The exception handler has a generic parameter: catch(Exception ex) . The IDE is VS. Sometimes the FTP library throws the following division by zero exception. The problem is it is not caught in the catch block, and the program crashes. Exceptions originated in my wrapper code are caught. Anyone has any

Python Exception Handling with in a loop

喜你入骨 提交于 2020-01-13 19:06:44
问题 An exception occurs when my program can't find the element its looking for, I want to log the event within the CSV, Display a message the error occurred and continue. I have successfully logged the event in the CSV and display the message, Then my program jumps out of the loop and stops. How can I instruct python to continue. Please check out my code. sites = ['TCF00670','TCF00671','TCF00672','TCF00674','TCF00675','TCF00676','TCF00677']` with open('list4.csv','wb') as f: writer = csv.writer(f