zoukankan      html  css  js  c++  java
  • asp.net mvc api 异常捕捉

    public Task Get(int id)
    {
    	var task = _taskRepository.Get(id);
    
    	if (task == null)
    	{
    		throw new HttpResponseException(new HttpResponseMessage
    		{
    			StatusCode = HttpStatusCode.NotFound,
    			Content = new StringContent("Task not found")
    		});
    	}
    
    	return task;
    }
    public Task Put(Task task)
    {
    	try
    	{
    		task = _taskRepository.Put(task);
    	}
    	catch (Exception)
    	{
    		throw new HttpResponseException(new HttpResponseMessage
    		{
    			StatusCode = HttpStatusCode.NotFound,
    			Content = new StringContent("Task not found")
    		});
    	}
    
    	return task;
    }

    //HttpStatusCode.NotFound (404)
  • 相关阅读:
    计算机思维
    easyui增删改查前段代码
    文本相似度分析
    布隆过滤器
    SQL Server事务
    堆排序(Heapsort)
    游标
    存储过程
    触发器
    Thread部分总结以及小例子
  • 原文地址:https://www.cnblogs.com/fx2008/p/2819149.html
Copyright © 2011-2022 走看看