exception-handling

unexpected execution of Exceptions in python

不问归期 提交于 2019-12-20 05:52:13
问题 I am novice to python and i came up with this problem. i have made a simple program for calculator. In add function, i have used try- except. when this line is encountered (if decide== 'no' or decide== 'n':), it displays the print line "return(" You have exited ")" but it also throws the exception. I cant understand why. import sys def menu(): print "calculator using functions" print "Choose your option:" print " " print "1) Addition" print "2) Subtraction" print "3) Multiplication" print "4)

Handing exception in BLL and return to client (either winforms or webforms)?

偶尔善良 提交于 2019-12-20 05:23:33
问题 I am looking for the best way to do exception handling, for example.. when an error occurs in the business logic layer, is the best way to stop the METHOD using a catch and return an EVENT to the presentation layer? What should this event contain? Or should i always BUBBLE up exceptions and handle them in the presentation layer? Anyone have some good links and required reading on this with regards to the best way of handling exceptions and how to handle them in the client ... For example if i

How to catch sun.awt.image.PNGImageDecoder$PNGException?

[亡魂溺海] 提交于 2019-12-20 04:37:41
问题 How to catch the following exception that is printed to the error console when trying to load a corrupted PNG file: sun.awt.image.PNGImageDecoder$PNGException: invalid depth at sun.awt.image.PNGImageDecoder.produceImage(Unknown Source) at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source) at sun.awt.image.ImageFetcher.fetchloop(Unknown Source) at sun.awt.image.ImageFetcher.run(Unknown Source) Following code makes the above output appear in the error console. But the exception is

How to handle exception in catch block?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 04:28:30
问题 I am trying to get the ideal way to handle exception. I googled & read that I should put try catch in the catch block as well to handle but what if any exception occurs in the nested block itself. try { int a = 10; int b = 0; int c = a / b; Console.WriteLine(c); Console.ReadKey(); } catch (Exception ex) { int a = 10; int b = 0; int c = a / b; Console.WriteLine(ex.Message.ToString()); Console.ReadKey(); } finally { Console.WriteLine("Some Exception"); } On googling I read that it should be

Maximum recursion depth error with getattr

谁说胖子不能爱 提交于 2019-12-20 04:26:24
问题 I have this code; class NumberDescriptor(object): def __get__(self, instance, owner): name = (hasattr(self, "name") and self.name) if not name: name = [attr for attr in dir(owner) if getattr(owner,attr) is self][0] self.name = name return getattr(instance, '_' + name) def __set__(self,instance, value): name = (hasattr(self, "name") and self.name) if not name: owner = type(instance) name = [attr for attr in dir(owner) if getattr(owner,attr) is self][0] self.name = name setattr(instance, '_' +

How do I run a cleanup code on the function exit?

戏子无情 提交于 2019-12-20 04:22:54
问题 C++ classes provide RAII idiom. Therefore you don't have to care about exceptions: void function() { // The memory will be freed automatically on function exit std::vector<int> vector(1000); // Do some work } But if you have (for some reasons) to use some pure C API, you have either to create C++ wrappers around it or to use try/catch blocks void function() { int *arr = (int*)malloc(1000*sizeof(int)); if (!arr) { throw "cannot malloc"; } try { // Do some work } catch (...) { free(arr); //

Exception Handling with Multiple catch block [duplicate]

二次信任 提交于 2019-12-20 04:09:56
问题 This question already has answers here : Order of catching exceptions in Java (3 answers) Closed 3 years ago . Here is my program. try { int a = 1/0; } catch(Exception e) { system.out.println("Exception block"+e); } catch(ArithmeticException e) { system.out.println("Inside ArithmeticException block"); } finally { system.out.println("Inside Finally block"); } In the above program i have two catch blocks and one finally block. Which catch block will execute? Because I define the parent catch

Print nested_exception with no nested_ptr

北城以北 提交于 2019-12-20 03:08:20
问题 I'm trying to print nested exceptions using the following example code from cppreference.com: void print_exception(const std::exception& e, int level = 0) { std::cerr << std::string(level, ' ') << "exception: " << e.what() << '\n'; try { std::rethrow_if_nested(e); } catch(const std::exception& e) { print_exception(e, level+1); } catch(...) {} } However, I get an abort if the innermost exception is a std::nested_exception rather than a std::exception (IE I throw a std::nested_exception , catch

Handling errors as exceptions. Best methods?

南楼画角 提交于 2019-12-20 02:49:28
问题 I'm trying to figure out if there's a good or better method for handling errors in PHP than what I'm doing below. I'd like to throw an exception if there's a problem with the parse_ini_file call. This works, but is there a more elegant way to handle errors? public static function loadConfig($file, $type) { if (!file_exists($file)) { require_once 'Asra/Core/Exception.php'; throw new Asra_Core_Exception("{$type} file was not present at specified location: {$file}"); } // -- clear the error self

What's the best way to handle the exceptions and how to deal with them in asp.net

霸气de小男生 提交于 2019-12-20 02:49:08
问题 First, I'm already familiar with the simple exception handling syntax but I'm asking about the best place, the best time and the best way to deal with them. I'm building an N-Layered application. so I think the DAL will sometime generate some errors to handle .. and I just learned about the SqlException class, what's the deal with that class ? I once saw a code that handles the SqlException then it handles Exception! After knowing the practice and where I'm going to handle them, I'm planning