exception-handling

try block inside while statement

江枫思渺然 提交于 2019-12-18 06:59:24
问题 I'm just starting out with Python 2.7 and I don't understand why something is happening: In the following code, an embellished version of an example from the python 2.7.2 tutorial, I get an unexpected result: while True: try: x = int(raw_input("Please enter a number: ")) break except ValueError: print "Oops! That was not a valid number. Try again..." else: print 'Thanks,',x,'is indeed an integer' finally: print 'all done, bye' When I put in an integer, the code ignores the else: statement and

Leak in Exception Code C++

徘徊边缘 提交于 2019-12-18 05:23:10
问题 I've been working with a school project, and one of the tasks is to make sure it doesn't leak at all. So, I ran my program through valgrind, and because I'm not using any dynamic memory allocation, I didn't think I would find anything. Oops, I did. Valgrind gave me this: ==22107== 16 bytes in 1 blocks are definitely lost in loss record 1 of 4 ==22107== at 0x100038915: malloc (vg_replace_malloc.c:236) ==22107== by 0x1000950CF: __cxa_get_globals (in /usr/lib/libstdc++.6.0.9.dylib) ==22107== by

Terminate application after unhandled exception

元气小坏坏 提交于 2019-12-18 05:12:31
问题 I have a problem in a WPF application. I wrote this code: public partial class App : Application { public App() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); } void MyHandler(object sender, UnhandledExceptionEventArgs e) { Exception exception = e.ExceptionObject as Exception; MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } ... } but when a unhandled exception happens, a lot of MessageBox appear to the

How to catch exceptions

荒凉一梦 提交于 2019-12-18 05:07:09
问题 This is my first application that will deal with exceptions properly. It's a WCF service. All the other before were simple apps just for myself. I have very small knowledge about exception handling in C#. I have a code like this: MembershipUser memUser = Membership.GetUser(username); DatabaseDataContext context = new DatabaseDataContext(); UserMembership user = UserMembership.getUserMembership(memUser); ItemsForUser itemUser = Helper.createItemForUser(ref item, memUser); Helper

Global handling exception in WPF app with Caliburn.Micro

荒凉一梦 提交于 2019-12-18 04:59:10
问题 Hi I try implement solution from this site im my WPF app for global exception handling. http://www.codeproject.com/Articles/90866/Unhandled-Exception-Handler-For-WPF-Applications.aspx I use Caliburn Micro as MVVM framework. Service I have in external assembly and it is injected in view model class with MEF. Here is my implementation for global exception handling in WPF app. App.xaml DispatcherUnhandledException="Application_DispatcherUnhandledException" Startup="Application_Startup" App class

Exception stack trace lost in Google Analytics v2 for Android?

帅比萌擦擦* 提交于 2019-12-18 04:52:19
问题 The stack trace is crucial to fix problems. In Android you can find nice reports in the Play store console. Unless you use Google Analytics V2. In this case Analytics seems to swallow the exceptions. Worse, Analytics seems to log only the first line of the exception and thus loosing the stacktrace. At least it is not shown in the error report. Here's a snip from our analytics.xml: <!-- Enable automatic exception tracking --> <bool name="ga_reportUncaughtExceptions">true</bool> <bool name="ga

Laravel 5 - How do I handle MethodNotAllowedHttpException

安稳与你 提交于 2019-12-18 04:38:07
问题 Where can I catch a MethodNotAllowedHttpException in Laravel 5+? In Laravel 4 I was able to do this in start/global.php . 回答1: // Exceptions/Handler.php use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; public function render($request, \Exception $e) { if ($e instanceof MethodNotAllowedHttpException) { // … } return parent::render($request, $e); } 回答2: In Laravel 5.4 , I did it like this: File location: app/Exceptions/Handler.php Add this code at the top of the file:

Sub-classing float type in Python, fails to catch exception in __init__()

拥有回忆 提交于 2019-12-18 04:05:41
问题 On Python 2.5 I need to use float numbers with a modified __str__() method. Also I need to know when the constructor fails. Why I can't catch exceptions raised from float.__init__() ? What is the best way to consult the numeric value of my derived float object? In my code I'm using float(self) . class My_Number(float): def __init__(self, float_string): try: super(My_Number, self).__init__(float_string) except (TypeError, ValueError): raise My_Error(float_string) def __str__(self): if int

Does it make sense to catch exceptions in the main(…)?

时间秒杀一切 提交于 2019-12-18 04:03:44
问题 I found some code in a project which looks like that : int main(int argc, char *argv[]) { // some stuff try { theApp.Run(); } catch (std::exception& exc) { cerr << exc.what() << std::endl; exit(EXIT_FAILURE); } return (EXIT_SUCCESS); } I don't understand why the exceptions are being catched. If they weren't, the application would simply exit and the exception would be printed. Do you see any good reason to catch exceptions here ? EDIT : I agree that it is good to print the exception error.

Does it make sense to catch exceptions in the main(…)?

僤鯓⒐⒋嵵緔 提交于 2019-12-18 04:03:15
问题 I found some code in a project which looks like that : int main(int argc, char *argv[]) { // some stuff try { theApp.Run(); } catch (std::exception& exc) { cerr << exc.what() << std::endl; exit(EXIT_FAILURE); } return (EXIT_SUCCESS); } I don't understand why the exceptions are being catched. If they weren't, the application would simply exit and the exception would be printed. Do you see any good reason to catch exceptions here ? EDIT : I agree that it is good to print the exception error.