getting error like unhadler (kernelbase.dll) openCV using C++ - opencv

I am doing simple program to detect webcam, it runs for some time but than I am getting the error message.
i took the code from,
https://thefreecoder.wordpress.com/2012/09/11/opencv-c-video-capture/
Unhandled exception at 0x74f22f71 (KernelBase.dll) in cvtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0109f524..
how to solve this problem.
Thank you very much in advance.

You could put the entire code within the try catch block
try
{
// ... Contents of your main
}
catch ( cv::Exception & e )
{
cout << e.msg() << endl;
}
This might help you! or Try with the debugger which line cause the exception.

Related

Catch NSMallocExceptioni using swift

From time to time my users find this error:
myapp(7383,0x1a1471000) malloc: * mach_vm_map(size=67125248) failed
(error code=3)
error: can't allocate region
set a breakpoint in malloc_error_break to debug 2017-04-06 20:33:58.152 myapp[7383:3724816] Terminating app due to uncaught
exception 'NSMallocException', reason: ' NSAllocateObject():
attempt to allocate object of class 'IOSByteArray' failed'
* First throw call stack: (0x183386db0 0x1829ebf80 0x183386cf8 0x183c6b34c 0x10076e6e4 0x10097d3ec 0x10097e35c 0x100977dd4
0x100977bd8 0x100978ff8 0x10096c950 0x10099685c 0x100997360
0x100979ca4 0x100976dcc 0x1002ec30c 0x100332fe4 0x100332e18
0x1003740c4 0x1004070f8 0x1004064ac 0x1021089b0 0x10210806c
0x1021089b0 0x102107710 0x1004072d8 0x1021087ec 0x1004071b0
0x102126bbc 0x10207b2d8 0x10207b374 0x188613dc4 0x1886d17d4
0x18878f0c8 0x18879ca80 0x1884ce5a4 0x18333c728 0x18333a4cc
0x18333a8fc 0x183264c50 0x184b4c088 0x188546088 0x100382a60
0x182e028b8) libc++abi.dylib: terminating with uncaught exception of
type NSException
The problem is that I can not find the callstack of the error.
I'm using XZ java lib ported into objc lib using j2objc application.
So, I can use this lib but I can't catch this error.
Google Analytics helps me and shows this line:
"&exd" =
"NSMallocException\nTrace:\n\nNSAllocateObject\nIOSByteArray_NewArray\nOrgTukaaniXzLzLZDecoder_initWithInt_withByteArray_\nnew_OrgTukaaniXzLzLZDeco";
So, It seems there is an error occurs:
void OrgTukaaniXzLzLZDecoder_initWithInt_withByteArray_(OrgTukaaniXzLzLZDecoder *self, jint var1, IOSByteArray *var2) {
NSObject_init(self);
self->start_ = 0;
self->pos_ = 0;
self->full_ = 0;
self->limit_ = 0;
self->pendingLen_ = 0;
self->pendingDist_ = 0;
JreStrongAssignAndConsume(&self->buf_, [IOSByteArray newArrayWithLength:var1]);
if (var2 != nil) {
self->pos_ = JavaLangMath_minWithInt_withInt_(var2->size_, var1);
self->full_ = self->pos_;
self->start_ = self->pos_;
JavaLangSystem_arraycopyWithId_withInt_withId_withInt_withInt_(var2, var2->size_ - self->pos_, self->buf_, 0, self->pos_);
}
}
But I can't find this error using swift:
do {
// ............
let inxz:OrgTukaaniXzXZInputStream = try OrgTukaaniXzXZInputStream(javaIoInputStream:in_)
// ..........
} catch {
print(error)
}
Please, help me
Swift's try/catch is completely separate from ObjC exceptions like this one. Those can only be caught with ObjC using #try and #catch. It is not possible to do in Swift.
That said, ObjC is generally not exception-safe. You have to be very careful using them, and in almost all cases the correct behavior after an exception is to crash the program. In this case, wrapped around exactly one call to a bridged function, it may be possible to effectively catch and deal with, but doing it correctly is a fairly subtle skill and not recommended if you can avoid it.
Almost certainly the reason for this error is that you're trying to allocate something too large. Rather than trying to catch the exception, I would look into why the object is so large and address that. In particular, I'd look at how large var1 is and make sure it's in a reasonable range. Also make sure it's not negative. The fact that you're using jint suggests that you might be seeing a mismatch with your integer types which I would absolutely expect to cause this kind of crash.
Thanks to #Sultan . He gave me an idea to use XZ pure C lib instead of Java>ObjC lib. Now this crash does not exist. It seems j2obc is wonder framework but it has got rare uncatchable errors.

unable catch exception new capture emgu CV c#

I'm doing projects using camera IP source onvif, but i can't catch exception when initialization new capture camera :
I'm start app debug but System Suspended by code new Capture(source ovif) , can't show exception. Thanks you.
try using "Exception" in catch statement.
try
{
....
}
catch(Exception ex)
{
MessageBox.Show(ex.ToSting());
}
Is your camera online and internet speed is enough to receive video? Try to decrease video resolution. Maybe you got same bug as I - https://github.com/emgucv/emgucv/issues/22

Understanding exception handling mechanism (control flow) in Dart

Assume we have this Dart code:
void main() {
try {
try {
throw null;
} catch(e) {
throw null;
} finally {
print('first');
}
} finally {
print('second');
}
}
When running this code in browser via http://try.dartlang.org
Produced result very expected.
first
second
Uncaught Throw of null.
But if running this code in Dart VM then result very unexpected.
second
Unhandled exception: Throw of null.
This looks like first termination block (finally) never be executed.
I cannot understand this behavior of the exception handling mechanism.
Of course, we can assume that this is a bug.
But exception handling is the cornerstone of any system.
How Dart developers can explain this disparity?
P.S.
I think this question related to theme "about programming" and asking it here are the right place and time?
This appears to be an error in the VM, as far as I can tell. I've filed a bug:
https://code.google.com/p/dart/issues/detail?id=11758&thanks=11758&ts=1373396821
I should add that while the code is illustrative of the differing VM and dart2js implementations, it is a little error prone. If you feel that your catch block is going to throw, wrap the code inside the catch block within its own try-catch.
And, yes, I agree that this is a fine question to ask on StackOverflow. Thanks for posting this.

Unhandled Exception Handling

In my MonoDroid application, when an unhandled exception occurs the application terminates without any messages. If I can reproduce the error on my local device I can debug it through Visual Studio without any problems.
However, on remote devices I am stuck for a solution.
I have tried the following in the Application class but it does not actually write my log file, unless I am running through the debugger in Visual Studio.
public override void OnCreate()
{
base.OnCreate();
AndroidEnvironment.UnhandledExceptionRaiser += new EventHandler<RaiseThrowableEventArgs>(AndroidEnvironment_UnhandledExceptionRaiser);
}
void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
{
// Write Log File
}
I disagree with #SpiritMachine's answer.
Mono documentation tells us:
Note: You cannot rely on the AppDomain.UnhandledException event as managed exceptions are never unhandled in MonoDroid; they are always intercepted at the Android/managed boundary within a catch(Exception) block.
Instead, I recommend that you do the following:
AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
{
// Do something...
};
Try something like this:
EDIT : This code cannot handle caught errors. Please see #Jim G.'s answer....
Personally, I would localise error handling to where you need it. The reason being, you don't know what your application state will be when this handler is recruited - you may be without resources that you're depending on to do the handling...

OpenCV2.4.2 unhandled exception on VideoCapture

I just installed OpenCV2.4.2 and created an OpenCV project using CMake. I don't get any compilation errors. I have several functions for processing images and I have 2 applications:
1- Processes data from a video
2- Processes simulated data.
Both applications are identical except from the data extraction from the video.
PROBLEM: The application processing video crashes with
Unhandled exception at 0x75d8a048 in program.exe Access violation
reading location 0x049f08c0.
It crashes in this part of the code, when reading frames:
cv::VideoCapture _video;
while(1)
{
// grab the frame
_video >> frame; <-------------CRASHES HERE
processFrame(frame);
}
So I guess there could be a problem with cv::VideoCapture class in OpenCV 2.4.2. How can I detect the problem and solve it?
EDIT
With video camera I managed to catch the error message:
OpenCV Error: Assertion failed (m.dims >= 2) in unknown function, file ..\..\..\
src\opencv\modules\core\src\matrix.cpp, line 268
OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowR
ange.end && _rowRange.end <= m.rows) in unknown function, file ..\..\..\src\open
cv\modules\core\src\matrix.cpp, line 283
Are you checking if the capture actually opened the file/camera ?
if(_video.isOpened()) { // check if capture succeeded
// do stuff
}
Not all codecs are supported per default. This depends on the library you use underneath to open the video. (This might be ffmpeg or quicktime).
Also you can catch the exception yourself, just to be on the safe side for future problems
try {
_video >> frame;
} catch (cv::Exception) {
cout << "An exception has accurred" << endl;
};

Resources