首页 > 其他分享 >异常处理(三)

异常处理(三)

时间:2022-10-31 08:01:25浏览次数:35  
标签:String 处理 会报 getUser user null 异常 email

 1 public class UserService {
 2   private UserRepo userRepo; // 依赖注入
 3   
 4   public User getUser(String telephone) {
 5     // 如果用户不存在,则返回null
 6     return null;
 7   }
 8 }
 9 
10 // 使用函数getUser()
11 User user = userService.getUser("18917718965");
12 if (user != null) { // 做NULL值判断,否则有可能会报NPE
13   String email = user.getEmail();
14   if (email != null) { // 做NULL值判断,否则有可能会报NPE
15     String escapedEmail = email.replaceAll("@", "#");
16   }
17 }

 

标签:String,处理,会报,getUser,user,null,异常,email
From: https://www.cnblogs.com/woaiheniunai/p/16842998.html

相关文章

  • 异常处理(五)
    1//address格式:"192.131.2.33:7896"2publicvoidparseRedisAddress(Stringaddress){3this.host=RedisConfig.DEFAULT_HOST;4this.port=RedisConfi......
  • 异常处理(四)
    1//使用空集合替代NULL2publicclassUserService{3privateUserRepouserRepo;//依赖注入45publicList<User>getUsers(StringtelephonePrefi......
  • 异常处理(八)
    1publicvoidfunc1()throwsException1{2//...3}456publicvoidfunc2()throwsException2{7//...8try{9func1();10}ca......
  • 异常处理(一)
    1publicclassRandomIdGeneratorimplementsIdGenerator{2 privatestaticfinalLoggerlogger=LoggerFactory.getLogger(RandomIdGenerator.class);34......
  • 异常处理(二)
    1//错误码的返回方式一:pathname/flags/mode为入参;fd为出参,存储打开的文件句柄。2intopen(constchar*pathname,intflags,mode_tmode,int*fd){3if(/*......
  • 处理器
    概念:处理器是os的核心,负责管理调度,分配计算机系统的重要资源,并行控制程序执行执行过程处理器依据程序计数器(pc)中的指令地址从内存中取一条指令取到的指令,放入指令寄存......
  • 异常处理及程序调试
    一、模拟幼儿园分苹果    二、模拟幼儿园分苹果(除数不能为0)     三、模拟幼儿园分苹果(每个人至少分到一个苹果   四、模拟幼儿园分苹果(应用......
  • 【自然语言处理(NLP)】基于Transformer的中-英机器翻译
    文章目录​​【自然语言处理(NLP)】基于Transformer的中-英机器翻译​​​​前言​​​​(一)、任务描述​​​​(二)、环境配置​​​​一、数据准备​​​​(一)、加载开发......
  • 【自然语言处理(NLP)】基于FNN网络的电影评论情感分析
    文章目录​​【自然语言处理(NLP)】基于FNN网络的电影评论情感分析​​​​前言​​​​(一)、任务描述​​​​(二)、环境配置​​​​一、IMDB数据准备​​​​(一)、参数设......
  • 深入 Spring 系列之静态资源处理
    前一段时间,WebIDE开源的过程中,无意间接触到webjars,觉得比较有趣,于是研究并整理了一下。webjars是将前端的库(比如jQuery)打包成Jar文件,然后使用基于JVM的包管理器(比如......