首页 > 其他分享 >在Android中用e.printStackTrace()

在Android中用e.printStackTrace()

时间:2023-09-06 14:03:59浏览次数:81  
标签:catch Exception Log 中用 printStackTrace vote Android


Is it a bad idea to use printStackTrace() in Android Exceptions?




up vote 35 down vote favorite

7




Is it a bad idea to use printStackTrace() in Android Exceptions like this?

} catch (Exception e) {
    e.printStackTrace();
}
} catch (Exception e) {
    e.printStackTrace();
}




java  android  exception  printstacktrace




 

add a comment

share improve this question


Oct 4 '10 at 12:26






jacknad

4,135 29 87 159





5 Answers



active oldest votes



up vote 22 down vote accepted


Yes, it is a bad idea. You should instead use Android's built-in log class specifically designed for these purposes: http://developer.android.com/reference/android/util/Log.html

It gives you options to log debug messages, warnings, errors etc.




 

add a comment

share improve this answer


Oct 4 '10 at 13:28






Nailuj

10.9k 10 54 84







up vote 26 down vote


I believe this is what you need:

catch (Exception e) {
     Log.e(TAG,Log.getStackTraceString(e)); 
}
catch (Exception e) {
     Log.e(TAG,Log.getStackTraceString(e)); 
}




 

share improve this answer


edited Nov 11 '11 at 22:25






sth

132k 34 214 315




Oct 25 '11 at 17:12






Adil Atilgan

279 3 3



标签:catch,Exception,Log,中用,printStackTrace,vote,Android
From: https://blog.51cto.com/u_16248677/7386454

相关文章

  • Android OTA升级之升级包生成脚本ota_from_target_files
    我们在这里主要分析OTA升级过程中对ota_from_target_files.py脚本的调用,这个脚本主的作用是生成各种OTA完整包和增量包。 以生成完整OTA包为例,假设我们的命令为:./build/tools/releasetools/ota_from_target_files-n input_file_dir/target_file.zip output_file_dir/outp......
  • android调试工具--dumpsys
    dumpsys执行格式为:dumpsys[option] 其中option参数可以为service和acitivity,参数service可以是系统中任意一个服务,比如meminfo服务显示内存信息,cpuinfo现实cpu信息参数acitivity可以现实所有的activity信息......
  • Android原生库和架构层通信的socket
    Android为原生库和架构层之间的通信提供了socket机制,在系统中为其提供了/dev/socket节点。/dev/socket节点是在init.rc文件初始化时生成的, $ls/dev/socketadbdcnddnsproxyddpmddpmwrapperfwmarkdims_datadims_qmidims_rtpdinstalldipacm_log_filelmkdlogdlogdrlo......
  • Android官方资料--Adoptable Storage
    AdoptableStorageINTHISDOCUMENTSecurityPerformanceandstabilityAndroidhasalwayssupportedexternalstorageaccessories(suchasSDcards),buttheseaccessorieswerehistoricallylimitedtosimplefilestorage,duetotheirexpectedimpermanence......
  • Android官方资料--OTA Package Tools
    OTAPackageToolsINTHISDOCUMENTFullupdatesIncrementalupdatesUpdatepackagesThe ota_from_target_files toolprovidedinbuild/tools/releasetools canbuildtwotypesofpackage: full andincremental.Thetooltakesthe target-files .zipfileproduc......
  • android编译报错:error: ro.build.fingerprint cannot exceed 91 bytes
    http://stackoverflow.com/questions/28776970/android-build-error-ro-build-fingerprint-cannot-exceed-91-bytesbuild/tools/post_process_props.py.Changelinesasfollows:PROP_NAME_MAX=31#PROP_VALUE_MAX=91PROP_VALUE_MAX=128PROP_NAME_MAX=31#PROP_V......
  • Android官方资料--Reducing OTA Size
    ReducingOTASizeINTHISDOCUMENTThebuilddifftoolChangestoreduceOTAsizeFileOrderBuildDirectoryTimestampsVersionStringsConsistentbuildtoolsAcommonproblemwithAndroidover-the-airupdates(OTAs)isthattheycontainchangedfilesthatdo......
  • Android Recovery UI浅析1——概览
    最近在作一个在recovery中显示文字的工作,所以对这块研究较多,现在把研究的一点新的结果分享出来,如果有什么错误也欢迎大家在下面评论。 Android的Recovery中,利用 boottable/recovery下的minui库作为基础,采用的是直接存取framebuffer的方式,来完成recovery中所需的各种UI的绘制。......
  • Android官方资料--Storage
    StorageINTHISDOCUMENTPermissionsRuntimepermissionsAndroidhasevolvedovertimetosupportawidevarietyofstoragedevicetypesandfeatures.AllversionsofAndroidsupportdeviceswithtraditionalstorage,whichincludesportableandemulateds......
  • Android官方资料--A/B System Updates
    A/BSystemUpdatesINTHISDOCUMENTOverviewBootloaderstateexamplesUpdateEnginefeaturesLifeofanA/BupdatePost-installstepImplementationKernelpatchesKernelcommandlineargumentsRecoveryBuildvariablesPartitionsFstabKernelslotargumentsOTApacka......