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)
  • 相关阅读:
    函数的定义
    编码转换
    bytes类型
    用py操作文件(file类的功能)
    HASH哈希
    二进制、bit、 bytes
    POJ3225
    POJ1436
    HDU1394
    HDU1272
  • 原文地址:https://www.cnblogs.com/fx2008/p/2819149.html
Copyright © 2011-2022 走看看