exception-handling

The Java interface doesn't declare any exception. How to manage checked exceptions of the implementation?

Let's say I have the following Java interface that I may not modify: public interface MyInterface { public void doSomething(); } And now the class implementing it is like this: class MyImplementation implements MyInterface { public void doSomething() { try { // read file } catch (IOException e) { // what to do...

Java force catch RuntimeException?

Is it possible to force java to make you catch RuntimeExceptions? Specifically I am working with the Spring framework and the whole Exception hierarchy is based upon RuntimeExceptions. A lot of the times I forget to try and catch the Exceptions. A specific example is when doing an LDAP query, or an SQL call. ...

following code comipling perfectly but showing runtime error . why?

//sample.h int calci(int &value) { if(value < 20) throw value; else return value; } class XYZ { int m_x; public: XYZ(int &x)try:m_x(x-calci(x)) { }catch (int &a) {} }; class ABC { int m_a; public: ABC():m_a(0) { } void foo() { XYZ xyz(10); } }; in...

Basic Python: Exception raising and local variable scope / binding

I have a basic "best practices" Python question. I see that there are already StackOverflow answers tangentially related to this question but they're mired in complicated examples or involve multiple factors. Given this code: #!/usr/bin/python def test_function(): try: a = str(5) raise b = str(6) except: ...

how to handle delete by illegal address

Suppose we have a situation like this. Suppose instead of "p = " we called some function(written by someone which invalidate our pointer). How to handle this problem? How to protect code from crashes? I know about and use boost smart pointers. But what to do if we have this situation. struct Test { int a; int b; int c; }; T...

getting detailed information about structured exceptions

My Visual C++ application is compiled with /EHA option, letting me catch structured exceptions (division by zero, access violation, etc). I then translate those exceptions to my own exception class using _set_se_translator(). My goal is to improve our logging of those types of exceptions. I can get the type of exception from the EXCEP...

java checked exception in a catch clause compilation error

Hi, I was expecting an compilation error in the following program because of the throw statement in the catch block as IOException is a checked exception and it is not caught by another try block within the catch block. But I am getting "Hurray!" printed. Any explanation would be much appreciated. According to JLS 11.2.3, http://java...

How do I display exception errors thrown by Zend framework

Hi guys I'm working with Zend framework and just hate the fact that I seem to encounter hundreds of exception errors like if I try to reference a non existant property of an object my application just dies and crashes. However I have no idea where to see these errors or how to be able to display them on screen. I've set display errors to...

Extending Throwable in Java

Java lets you create an entirely new subtype of Throwable, e.g: public class FlyingPig extends Throwable { ... } Now, very rarely, I may do something like this: throw new FlyingPig("Oink!"); and of course elsewhere: try { ... } catch (FlyingPig porky) { ... } My questions are: Is this a bad idea? And if so, why? What could've...

Is it possible to call the main(String[] args) after catching an exception?

I'm working on a Serpinski triangle program that asks the user for the levels of triangles to draw. In the interests of idiot-proofing my program, I put this in: Scanner input= new Scanner(System.in); System.out.println(msg); try { level= input.nextInt(); } catch (Exception e) { System.out.print(warning); //restart main met...

Ideal way to set global uncaught exception Handler in Android

I want to set a global uncaught exception handler for all the threads in my Android application. So, in my Application subclass I set an implementation of Thread.UncaughtExceptionHandler as default handler for uncaught exceptions. Thread.setDefaultUncaughtExceptionHandler( new DefaultExceptionHandler(this)); In my impl...

ASP.MVC 1.0 serialization error not trapped by IExceptionFilter

Hi, I'm using ASP.NET MVC 1.0 and have exeption handling manged by a global controller activated by the HandleException attribute on the main controller. I've noticed that if I have an action invoked by an AJAX call, and that action fails with an internal ASP.NET error (e.g. I've tried to serialize an anonymous object) then the ASP.MVC...

Exception handling policy in libraries

When building a .NET library, what's your exception handling policy? In specific, what's your policy about handling exceptions inside library calls and exposing them to calling code? For example, Would you treat a library function as any other, thus letting all exceptions it can't handle flow out of it as-is? Would you create a custom...

What is the suggested way to show exception messages on UI which were produced in Business Layer?

Hi, Is there a pattern OR 'a best practice' on creating user's friendly messages in the presentation layer by using exceptions which were thrown from the Business Layer? Actually in many cases I prefer to throw Application Exceptions and this is forcing me to catch them on UI (aspx.cs pages). And if the process is complex which may pro...

Java Mail timeout & connectiontimeout handling

Hi, I'm using JavaMail to send email requests to an SMTP server. I would like to set both "mail.smtp.connectiontimeout" and "mail.smtp.timeout" properties within my code. Programmatically, I want to catch both when timeout and/or connectiontimeout operations are reached in Java and handle things accordingly. Handling in the sense, I n...

How to display invalid call exceptions from fluent controller in MVCContrib?

How can I pass the exception thorwn by the action in MVCContrib.FluentController CheckValidCall(action)? [ExportModelStateToTempData] public ActionResult Index(int itemId, int page) { return CheckValidCall(() => MyService.GetResults(itemId, page)) .Valid(x => View(x)) .Invalid(() => RedirectT...

c++ exceptions and program execution logic

Hello everyone, I have been thru a few questions but did not find an answer. I wonder how should the exception handling be implemented in a C++ software so it is centralized and it is tracking the software progress? For example, I want to process exceptions at four stages of the program and know that exception happened at that specifi...

[C#] how to do Exception Handling & Tracing

Hi all, i am reading some C# books, and got some exercise don't know how to do, or not sure what does the question mean. Problem: After working for a company for some time, your skills as a knowledgeable developer are recognized, and you are given the task of “policing” the implementation of exception handling and tracing in the source...

Catch All (handled or unhandled) Exceptions

Hi, I want to catch all exceptions raised (handled or unhandled) to log them. for unhandled i use ThreadExceptionEventHandler and UnhandledExceptionEventHandler but i want to catch and exceptions that are in try catch block with or without (Exception e). It's possible to inherit the exceptions class to create a general event? ...

What should I know about Structured Exceptions (SEH) in C++?

What important points about Structured Exceptions should every C++ developer know? ...