Android Forums

Go Back   These FORUMS ARE DISABLED!! OUR NEW FORUMS ARE AT http://androidforum.com/ > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
 
 
LinkBack Thread Tools Display Modes
Old 12-21-2008, 06:24 PM   #1
Junior Member
 
Join Date: Dec 2008
Posts: 4
Friends: 0
View wjjsun's Profile   View wjjsun's Photo Album   View wjjsun's Blog   View Social Groups
Hi,

When I try to compile a C++ code with try/catch statements, it can not pass build.
Does anyone know if try/catch is supported or not in android? Or how can I fix this issue?

test code:
#include <stdio.h>

int main()
{
try
{
printf("try statement\n");
throw 1;
}
catch (...)
{
printf("catch exeption here\n");
}
}

Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm

LOCAL_SRC_FILES := \
./test.cpp

LOCAL_CFLAGS += -fexceptions

LOCAL_LDFLAGS += -lstdc++

LOCAL_MODULE := test

include $(BUILD_EXECUTABLE)

compile error:
mydroid/try_catch/./test.cpp:9: undefined reference to `__cxa_allocate_exception'

wjjsun
2008/12/22
wjjsun is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Old 01-01-2009, 05:10 PM   #2
Junior Member
 
Join Date: Jan 2009
Location: Cardiff, Wales
Posts: 28
Friends: 0
View Emyr's Profile   View Emyr's Photo Album   View Emyr's Blog   View Social Groups
Wouldn't it be easier just to do it in Java like everyone else?

If you're really fussy about your limited coding skillset, read this thread:
http://groups.google.com/group/andro...7594c37a?pli=1
Emyr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Old 01-01-2009, 09:36 PM   #3
Junior Member
 
Join Date: Dec 2008
Posts: 4
Friends: 0
View wjjsun's Profile   View wjjsun's Photo Album   View wjjsun's Blog   View Social Groups
Thanks,Emyr,

I want to porting a C/C++ project to android native code, which means it's impossible to rewrite it in JAVA language. just as tcpdump project is porting to android by default.

But during porting, I found try/catch statement will cause compile problem.

Any idea to handle such case?

BRs
wjjsun
2009/01/02
wjjsun is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Old 01-15-2009, 10:59 AM   #4
Junior Member
 
Join Date: Jan 2009
Posts: 1
Friends: 0
View jjagogo's Profile   View jjagogo's Photo Album   View jjagogo's Blog   View Social Groups
Google implemented their own libc and libc++ routines instead of using the gnu software. The goal was to get around some licensing issues and create a light weight set of libraries. They decided NOT to implement exceptions in there implementation. You could cross compile a linux for ARM and install the libraries needed for exceptions, but since space is limited you'll probably have to put it in the SD card.
jjagogo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Old 01-15-2009, 02:12 PM   #5
Member
 
Ageless Stranger's Avatar
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 74
Friends: 1
View Ageless Stranger's Profile   View Ageless Stranger's Photo Album   View Ageless Stranger's Blog   View Social Groups
Send a message via MSN to Ageless Stranger Send a message via Yahoo to Ageless Stranger
I have been programming for over 18 years and never had the need to use one try or catch statement, and I use c/c++ most of the time. I know the benefits of using try/catch, but I guess I am too pedantic when it comes to coding, checking pointers whenever I use them, checking return types and acting on them in a structured way. Things like try/catch and garbage collection has made programmers lazy, but I guess this is the "new" thing (pun intended) and I'm old and set in my ways. Why stop at native c or c++ when you can do it in assembler? hmm maybe that is going a little too far, but I wouldnt mind coding in fortran for the G1
Ageless Stranger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Old 01-15-2009, 02:25 PM   #6
Junior Member
 
Join Date: Jan 2009
Location: Cardiff, Wales
Posts: 28
Friends: 0
View Emyr's Profile   View Emyr's Photo Album   View Emyr's Blog   View Social Groups
Exceptions thrown by library functions in Java make sure programmers don't ignore type conversion errors and errors they might not usually consider... Or at least that's what I'd like to believe!
Emyr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
NullPointerException for Very Basic Code baran_khan Android Development, Answers, Tutorials, and Code Snippets 6 11-25-2011 10:11 AM
40% off invisible shield coupon code Andor G1 2 10-31-2008 01:10 PM
Compiler for My Native Code? on Windows? siimon Android Development, Answers, Tutorials, and Code Snippets 0 06-26-2008 06:27 AM
Linux Kernal Source Code? breaded Android Development, Answers, Tutorials, and Code Snippets 0 06-05-2008 01:48 PM
Improved Code Tags? dr0ne Site Feedback 0 05-15-2008 08:48 AM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 05:43 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2012 TalkAndroid.com. All rights reserved.