exception-handling

How to handle GORM exceptions

拥有回忆 提交于 2019-12-06 07:56:38
问题 I'm trying to implement exception handling for Optimistic lock type exceptions that are thrown by Hibernate but I've encountered a strange issue. It seems I'm unable to catch any Gorm exceptions. For example I have this code in my service: try { User user = User.get(1); Thread.sleep(10000); user.viewedAt(new Date()); user.save(flush:true); } catch (OptimisticLockingException ex) { log.error("Optimistic lock exception"); } catch (StaleObjectStateException ex) { log.error("Optimistic lock

what is the use of assert in java [duplicate]

柔情痞子 提交于 2019-12-06 07:40:45
This question already has answers here : Closed 7 years ago . Possible Duplicate: What does assert do? assert tests the programmer's assumption during development without writing exception handlers for an exception This is what i got, when i was searching about the assert . Apart from this, people also said, it is alternative of exception handling. Assertion will come into the picture when you don't want to take the time to write the exception handling code. But, i didn't get the working and uses. Anyone explain this example. class AssertExample { public static void main(String[] args) { int x

How to force an application crash when AccessViolationException is detected

旧时模样 提交于 2019-12-06 07:31:48
We use an automated crash reporting tool (namely http://crashrpt.sourceforge.net ) for generating crash reports. So if a piece of unmanaged code fails by accessing a NULL pointer for example, the application crashes, the crash reporting tool activates and we get usable stack trace for diagnosing and grouping issues. The problem is that .NET seems to interfere with crash handling in some cases. One sample is the following: this.Dispatcher.BeginInvoke((ThreadStart)delegate { // Send message to unmanaged control for performing a specific task. User32.SendMessage(...); }, DispatcherPriority.Input)

How do identify STATUS_INVALID_CRUNTIME_PARAMETER exception

左心房为你撑大大i 提交于 2019-12-06 07:31:12
Platform is Windows 7 SP1. I recently spent some time debugging an issue that was caused because a code was passing an invalid parameter to one of the "safe" CRT functions. As a result my application was aborted right away with no warning or anything -- not even a crash dialog. At first, I tried to figure this out by attaching Windbg to my application. However when the crash happened, by the time the code broke into Windbg pretty much every thread had been killed save for ONE thread on which Windbg had to break into. There was no clue as to what was wrong. So, I attached Visual Studio as a

Globally catch exceptions thrown from WCF async calls in a background thread

倖福魔咒の 提交于 2019-12-06 07:29:40
I have a WPF application that communicates with a WCF service. I'm currently calling my WCF service from my ViewModels (I'm using the MVVM pattern) using the following async based pattern: public async override void MyCommandImplementation() { using (var proxy = new MyProxy()) { var something = await proxy.GetSomethingAsync(); this.MyProperty = something; } } As I'm following the MVVM pattern, I have ICommand public properties that are exposed by my ViewModels, so associated command implementation won't return Task<T> objects as they are like event handlers. So the exception handling is

Propagating exceptions through dlsym cython

你说的曾经没有我的故事 提交于 2019-12-06 07:18:52
I am unable to propagate exceptions through dlsym. I use dlsym to load a cythonized python file. I made a minimal working example below so you can try it yourself: I have a pyx file, c_fun.pyx, which I compile to a C file using Cython. Then I'm using dlsym to load in the so file in another program, say use_fun.c++. You can use ./compile.sh to compile the files. On executing ./test, the program crashes with a segmentation fault. #c_fun.pyx: cdef public double _myfunction(double x) except*: a=1/0 # This does not propagate an exception. Comment to make the example work return x**2-x # This works.

Lifetime of a thrown object caught by reference

陌路散爱 提交于 2019-12-06 07:13:58
问题 The C++ Standard, paragraph 15.1.4 sais: The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in 3.7.3.1. The temporary persists as long as there is a handler being executed for that exception. I'm wondering why this code crashes (I know that it's not best practice): class magicException { private: char* m_message; public: magicException(const char* message) { m_message = new char[strlen(message) + 1]; strcpy(m_message, message);

Uncaught exception handler not called

倾然丶 夕夏残阳落幕 提交于 2019-12-06 07:00:02
问题 I'm trying to catch exceptions on my Mac app so that I can log them in a custom log file. I'm implementing the exception handler like this: void uncaughtExceptionHandler(NSException *exception) { NSLog(@"It Works!"); } And I'm setting it in my -applicationDidFinishLaunching: method like this: NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); Then I cause an exception to test it like this: [[NSArray arrayWithObject:@"object"] objectAtIndex:1]; The exception gets logged to the console,

Handling exceptions in a Swing UI (low level to high level and exception wrapping)

风流意气都作罢 提交于 2019-12-06 06:58:38
I wish to handle Exceptions in a meaningful way in a Swing application. The following is inside an actionPerformed method. The UiUtils#showError displays a JOptionPane with a button that shows/hides the stack trace. ApplicationException is a custom class to translate low level Exceptions to something a user would understand. One issue is that I'm not sure how to handle a NullPointerException that propagates up if a user doesn't select a file in the JFileChooser before this code. The exportData method purposefully checks for null on entry so no file handling is done. Also, it seems that it

custom exception behavior in symfony2

一笑奈何 提交于 2019-12-06 06:37:53
问题 Im trying to figure out how to make a custom exception behavior. When i throw a exception using throw new \Exception('Error occurred with your request please try again'); I automatically get status 500 and the message as internal server error However i would instead like my response to include my exception message instead of just internal server error so for it to display something like so: { "error":{ "code":500, "message":"Error occurred with your request please try again" } } and on top of